基本上我想要尝试做的是根据有多少系列改变我的高级图表主题的配色方案。这样的事情可以实现吗?我应该将此代码放在主题内或每个图表内吗?
EG
var colors = [];
var series = chart.series;
if (series == 2) {
colors = ['blue', 'red'];
} else if (series == 3) {
colors = ['blue', 'red', 'black'];
} else if (series == 4) {
colors = ['blue', 'red', 'black', green];
}
的jsfiddle:http://jsfiddle.net/tbo2o4Lm/
按照以下操作顺序操作很容易:
示例代码:
var series = [{
data: [1, 2]
}, {
data: [2, 3]
}, {
data: [1, 4]
}];
Highcharts.theme = {
colors: (function() {
var colors = ['red', 'blue', 'green', 'orange'];
return colors.length <= series.length ? colors : colors.slice(0, series.length);
})()
}
// Apply the theme
Highcharts.setOptions(Highcharts.theme);
var chart = Highcharts.chart('container', {
series: series
});