我认为实现此目标的最佳方法是使用以下功能,该功能可以计算出plotLine并将其添加到图表中。
events: {
load() {
let chart = this,
sum = 0,
i = 0,
medianValue;
chart.series.forEach(s => {
s.points.forEach(p => {
sum += p.y
i++;
})
})
medianValue = sum / i;
chart.yAxis[0].update({
plotLines: [{
value: medianValue,
color: 'red',
width: 10
}]
})
}
}
演示:https://jsfiddle.net/BlackLabel/u8a4so3r/
API:https://api.highcharts.com/highcharts/yAxis.plotLines
API:https://api.highcharts.com/highcharts/chart.events.load
API:https://api.highcharts.com/class-reference/Highcharts.Axis#update