Click an event when you click on a chart

I have a series of line charts built using high charts, and a tooltip for them.

http://jsfiddle.net/FhF3A/

$('#container').highcharts({ tooltip: { shared: true }, series: [{ name: 'Berlin', data: [-0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0] }, { name: 'London', data: [3.9, 4.2, 5.7, 8.5, 11.9, 15.2, 17.0, 16.6, 14.2, 10.3, 6.6, 4.8] }] }); 

What should be the best way to capture the dblclick event and get the hover axis value of y on the chart?

+7
source share
2 answers

This is pretty well explained in the documentation .

What you can do is something like THIS .

Therefore, you should add something like this to your code:

 chart: { events: { click: function(event) { alert ( 'x: '+ Highcharts.dateFormat('%Y-%m-%d', event.xAxis[0].value) +', ' + 'y: '+ event.yAxis[0].value ); } } } 

Here is an example of this implementation.

Update

To make sure that clicking on the chart itself is also enabled, add the following:

 plotOptions: { series: { cursor: 'pointer', point: { events: { click: function() { alert ('Category: '+ this.category +', value: '+ this.y); } } } } }, 

You can see a working example HERE

+6
source

if you want to make one click on a line, you can do this by setting plotOptions> line, as in http://api.highcharts.com/highcharts#plotOptions.line.events.click .

Now, if you need a double click, you can have a global variable that tracks the number of clicks in the same click event.

hopes help

+1
source

Source: https://habr.com/ru/post/1490066/


All Articles