您可以从renderGridLine
原型包装Tick
方法:
(function(H) {
var colors = ['#0050d1', '#de0735', '#00e031', '#ffb300', '#c800ff'],
i = 0;
H.wrap(H.Tick.prototype, 'renderGridLine', function(proceed) {
if (!this.axis.isXAxis) {
this.axis.options.gridLineColor = colors[i];
if (this.isLast) {
i = 0;
} else {
i++;
}
}
proceed.apply(this, Array.prototype.slice.call(arguments, 1));
});
}(Highcharts));
实时演示: https://jsfiddle.net/BlackLabel/45fh27tc/
文档: https://www.highcharts.com/docs/extending-highcharts/extending-highcharts
或在load
事件中设置彩色非洲图表初始化:
var colors = ['#0050d1', '#de0735', '#00e031', '#ffb300', '#c800ff'];
Highcharts.chart('container', {
chart: {
...
events: {
load: function() {
var yAxis = this.yAxis[0];
yAxis.tickPositions.forEach(function(tPos, i) {
yAxis.ticks[tPos].gridLine.attr({
stroke: colors[i]
});
});
}
}
},
...
});
实时演示: https://jsfiddle.net/BlackLabel/xbLtur48/
API参考:
https://api.highcharts.com/class-reference/Highcharts.SVGElement#attr