Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Highcharts chart click event fired on click of the reset zoom button (bug?)

Tags:

highcharts

I have a click event on the chart, but if you use the zoom and want to reset the zoom, the click event is also fired.

I've the following chart settings:

$('#container').highcharts({
        chart: {
            type: 'line',
            marginRight: 130,
            marginBottom: 25,
            zoomType: 'x',
            events: {
                click: function (event) {
                    alert('chart click!');
                }
            }
        }...

see working example: http://jsfiddle.net/2Y3ah/

Well this looks like a bug or if it's as designed how to block the click event if the reset zoom button is clicked.

like image 516
RubenR Avatar asked Apr 03 '13 14:04

RubenR


3 Answers

A dirty way can be to look at the srcElement

for example test the following (check if firstChild not null ...)

event.srcElement.firstChild.data === "Reset zoom"
like image 147
Ronan Quillevere Avatar answered Nov 16 '22 10:11

Ronan Quillevere


You can recognise if button is clicked, by event.target http://jsfiddle.net/2Y3ah/3/

 if(!($(event.target)[0].textContent))
                        alert('chart click!');

http://api.jquery.com/event.target/

like image 36
Sebastian Bochan Avatar answered Nov 16 '22 09:11

Sebastian Bochan


This is the ultimate solution. Just set the following config to the Chart:

    $('#container').highcharts({
        chart: {
            resetZoomButton: {
                relativeTo: 'chart'
            }
        }
    });
like image 1
ruff Avatar answered Nov 16 '22 10:11

ruff