gpt4 book ai didi

javascript - Highcharts sunburst - 覆盖全局颜色

转载 作者:行者123 更新时间:2023-12-01 01:06:37 26 4
gpt4 key购买 nike

是否可以覆盖旭日图的全局图表颜色?我尝试了多种方法,但似乎都不起作用。

请检查这个 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,但似乎都不起作用。

有效的方法是在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: {...}
});

现场演示:https://jsfiddle.net/BlackLabel/be61rtz2/

API引用:https://api.highcharts.com/highcharts/colors

关于javascript - Highcharts sunburst - 覆盖全局颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55575062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com