问题描述:highstock使用蜡烛图不能设置Axis的crosshair的渐变色
解决方案:
需要调用方法addEvent(),参考如下代码:
Highcharts.chart('container', {
chart: {
type: 'candlestick'
},
title: {
text: ''
},
xAxis: {
crosshair: {
color: {
linearGradient: {
x1: 0,
x2: 0,
y1: 1,
y2: 0
},
stops: [
[0, 'red'],
[1, 'blue']
]
}
}
},
series: [{
color: 'green',
lineColor: 'green',
upColor: 'red',
upLineColor: 'red',
data: [
[1317888000000, 372.5101, 375, 372.2, 372.52],
[1317888060000, 372.4, 373, 372.01, 372.16],
[1317888120000, 372.16, 372.4, 371.39, 371.62],
[1317888180000, 371.62, 372.16, 371.55, 371.75],
[1317888240000, 371.75, 372.4, 371.57, 372],
[1317888300000, 372, 372.3, 371.8, 372.24],
[1317888360000, 372.22, 372.45, 372.22, 372.3],
[1317888420000, 372.3, 373.25, 372.3, 373.15],
[1317888480000, 373.01, 373.5, 373, 373.24],
[1317888540000, 373.36, 373.88, 373.19, 373.88],
[1317888600000, 373.8, 374.34, 373.75, 374.29],
[1317888660000, 374.29, 374.43, 374, 374.01],
[1317888720000, 374.05, 374.35, 373.76, 374.35],
[1317888780000, 374.41, 375.24, 374.37, 374.9],
]
}]
});
Highcharts.addEvent(Highcharts.Axis, 'afterDrawCrosshair', function(point) {
if (this.cross) {
let path = this.cross.pathArray;
path[1][1] += 0.001;
this.cross.attr({
d: path
})
}
});
代码演示链接: https://jsfiddle.net/Ricardo_lqs/o7xrv12L/2/.
如果觉得对你有帮助,请作者喝杯咖啡