Highcharts sunburst - 覆盖全局颜色
Highcharts sunburst - override global colors
是否可以覆盖旭日图的全局图表颜色?我尝试了多种方法,但 none 似乎有效。
请检查此 fiddle:https://jsfiddle.net/max1tdzh/
chart: {
height: '100%',
colors: ['#ff0000', '#00ff00', '#0000ff']
},
plotOptions: {
series: {
colors: ['#ff0000', '#00ff00', '#0000ff']
},
sunburst: {
colors: ['#ff0000', '#00ff00', '#0000ff']
}
},
我试过设置 chart.colors、plotOptions.sunburst.colors 和 plotOptions.series.colors,none 似乎可行。
有效的是在 series.data 数组中的特定数据点上设置颜色 属性,但此解决方案并不好,因为它需要使用自定义辅助函数遍历所有元素,如下所示:
let colorIndex = 0;
return data.map((point) => {
if (!point.parent) {
const color = colors[colorIndex % colors.length];
colorIndex++;
return { ...point, color };
}
return point;
});
您需要直接在图表配置对象中设置颜色:
Highcharts.chart('container', {
colors: ['#ff0000', '#00ff00', '#0000ff'],
chart: {
height: '100%',
},
...,
plotOptions: {...}
});
是否可以覆盖旭日图的全局图表颜色?我尝试了多种方法,但 none 似乎有效。
请检查此 fiddle:https://jsfiddle.net/max1tdzh/
chart: {
height: '100%',
colors: ['#ff0000', '#00ff00', '#0000ff']
},
plotOptions: {
series: {
colors: ['#ff0000', '#00ff00', '#0000ff']
},
sunburst: {
colors: ['#ff0000', '#00ff00', '#0000ff']
}
},
我试过设置 chart.colors、plotOptions.sunburst.colors 和 plotOptions.series.colors,none 似乎可行。
有效的是在 series.data 数组中的特定数据点上设置颜色 属性,但此解决方案并不好,因为它需要使用自定义辅助函数遍历所有元素,如下所示:
let colorIndex = 0;
return data.map((point) => {
if (!point.parent) {
const color = colors[colorIndex % colors.length];
colorIndex++;
return { ...point, color };
}
return point;
});
您需要直接在图表配置对象中设置颜色:
Highcharts.chart('container', {
colors: ['#ff0000', '#00ff00', '#0000ff'],
chart: {
height: '100%',
},
...,
plotOptions: {...}
});