I have been working on a web application which used Highcharts for charting data. As such, one of the requirement is that when I hover my mouse on the chart (screenshot below – assuming the arrow is the mouse cursor), a vertical line will automatically display of where the mouse cursor was. Aside from that, the vertical line will also move along the x-axis as the mouse cursor moves sideways within the chart.
This is the sample chart.
This is my highchart configuration script:
JavaScript
x
62
62
1
function plotChartData(dataseries, xtitle)
2
{
3
myChart = new Highcharts.Chart({
4
chart: {
5
renderTo: 'trendspace',
6
type: 'line',
7
zoomType: 'xy',
8
panning: true,
9
panKey: 'shift',
10
plotBorderWidth: 1
11
},
12
title: {
13
text: ''
14
},
15
legend: {
16
layout: 'horizontal',
17
align: 'left',
18
itemDistance: 10,
19
borderWidth: 0,
20
itemMarginTop: 0,
21
itemMarginBottom: 0,
22
padding: 20
23
},
24
plotOptions: {
25
series: {
26
states: {
27
hover: {
28
enabled: false
29
}
30
},
31
dataLabels: {
32
enabled: false,
33
format: '{y}'
34
},
35
allowPointSelect: false
36
}
37
},
38
xAxis: {
39
type: 'datetime',
40
labels: {
41
rotation: -65,
42
style: {
43
fontSize: '9px',
44
fontFamily: 'Verdana, sans-serif'
45
}
46
}
47
},
48
yAxis: {
49
gridLineColor: '#DDDDDD',
50
gridLineWidth: 0.5
51
},
52
series: [{
53
name: xtitle,
54
data: dataseries,
55
tooltip: {
56
pointFormat: '{series.name}: <b>{point.y}</b><br/>',
57
valueDecimals: 2
58
}
59
}]
60
});
61
}
62
I browsed through the Highcharts API and I can’t find the exact method or configuration to make that happen. Is this doable in Highchart? How can I achieve this?
Advertisement
Answer
Try setting your tooltip crosshairs
JavaScript
1
4
1
tooltip: {
2
crosshairs: [true]
3
}
4
Or as @IronGeek wrote, use xAxis.CrossHairs