我有一张2轴的图表。
我需要一条尖峰线指向女巫图表线来自女巫yAxis就像这样
我想要的例子:
我尝试使用十字准线,但这不是我想要的,因为它指向yAxis,我想只指向一个yAxis。
十字准线示例
有人知道怎么做吗?
这是代码:
Highcharts.chart('container', {
chart: {
marginRight: 80 // like left
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
crosshair:true
},
yAxis: [{
lineWidth: 1,
title: {
text: 'Primary Axis'
},
crosshair:true
}, {
lineWidth: 1,
opposite: true,
title: {
text: 'Secondary Axis'
}
}],
series: [{
data: [29.9, 71.5, 106.4, 129.2, 144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4]
}, {
data: [144.0, 176.0, 135.6, 148.5, 216.4, 194.1, 95.6, 54.4, 29.9, 71.5, 106.4, 129.2],
yAxis: 1
}]});
在mouseOver
点事件中,你可以使用Highcharts.SVGRenderer
添加一个path
元素,这将是尖峰线:
function drawSpikeLine() {
var point = this,
chart = point.series.chart,
plotLeft = chart.plotLeft,
opposite = point.series.yAxis.opposite,
x1 = point.plotX + plotLeft,
x2 = opposite ? plotLeft + chart.plotWidth : plotLeft,
y = point.plotY + chart.plotTop;
point.spikeLine = [];
point.spikeLine[0] = chart.renderer.path(['M', x1, y, 'L', x2, y])
.attr({
'stroke-width': 2,
stroke: 'red'
})
.add();
point.spikeLine[1] = chart.renderer.path([
'M', x1, y,
'L', x1, chart.plotTop + chart.plotHeight
])
.attr({
'stroke-width': 2,
stroke: 'red'
})
.add();
}
function removeSpikeLine() {
this.spikeLine[0].destroy();
this.spikeLine[1].destroy();
}
Highcharts.chart('container', {
...,
plotOptions: {
series: {
point: {
events: {
mouseOver: drawSpikeLine,
mouseOut: removeSpikeLine
}
}
}
}
});
现场演示:http://jsfiddle.net/BlackLabel/cd18h7v2/
API参考:
https://api.highcharts.com/class-reference/Highcharts.SVGRenderer#path
https://api.highcharts.com/highcharts/plotOptions.series.events