Highcharts Spider Highchart-每个网格线的颜色不同
我使用海图(蜘蛛) 我想为y轴的每条网格线指定不同的颜色。 有没有什么优雅的方法可以做到这一点(我的意思是-没有jQuery和复杂的css选择器) 请看附图Highcharts Spider Highchart-每个网格线的颜色不同,highcharts,Highcharts,我使用海图(蜘蛛) 我想为y轴的每条网格线指定不同的颜色。 有没有什么优雅的方法可以做到这一点(我的意思是-没有jQuery和复杂的css选择器) 请看附图 您可以从勾选原型中包装renderGridLine方法: (function(H) { var colors = ['#0050d1', '#de0735', '#00e031', '#ffb300', '#c800ff'], i = 0; H.wrap(H.Tick.prototype, 'renderG
您可以从
勾选原型中包装renderGridLine
方法:
(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));
现场演示:
文档:
或在<代码>加载代码>事件中设置彩色afrer图表初始化:
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]
});
});
}
}
},
...
});
现场演示:
API参考:
@Sebastian Wędzel你能试着回答吗?没有比这更优雅的方法了?嗨@user5260143,我认为这是一个非常优雅的解决方案:)但你也可以在加载事件中更改颜色:我将使用你在评论中建议的解决方案。目前我只将此评论标记为有效,因为我希望其他人尝试通过配置帮助我实现它。谢谢。当然,没问题,但是仅仅通过选项是不可能实现的。嗨,这个表达式向我返回空对象:yAxis.ticks[tPos]