score:39

Accepted answer

if you want to add an event listener after the chart is already created, the documentation provides some insight regarding extending highcharts:

events can be added to the instance through framework event binding. if your framework is jquery, you can for example run $(chart).bind('load', somefunction);

there is even some mention in the "hooking up to chart.init" section (on the same page) as to how you might bind an event after the chart has rendered, but it is a more invasive solution. i've adapted the code sample below with some modifications:

// general, global event listener
var globalcallback = function (chart) {

    // specific event listener
    highcharts.addevent(chart.container, 'click', function (e) {
        e = chart.pointer.normalize();
        console.log('clicked chart at ' + e.chartx + ', ' + e.charty );
    ​});

    // specific event listener
    highcharts.addevent(chart.xaxis[0], 'aftersetextremes', function (e) {
        console.log('set extremes to ' + e.min + ', ' + e.max);
    });
}

// add `globalcallback` to the list of highcharts callbacks
highcharts.chart.prototype.callbacks.push(globalcallback);

you can also take a look at their example jsfiddle for this scenario.


Related Query

More Query from same tag