There are occasions where we are unable to attach the proper event handlers to a chart before the chart has rendered. Fortunately, in these cases, we can leverage some handy Highcharts functions.
For setting up a basic page and installing jQuery and Highcharts, refer to the Getting ready section of the Creating your first chart recipe from Chapter 1, Getting Started with Highcharts.
To get started, perform the following steps:
Create an event handler for when we click on a series, as shown in the following code:
var clickSeries = function (event) { console.log('Captured click event!', event); };
Get a reference to your chart as shown in the following code:
var chart = $('#container').highcharts(); // Alternatively, if the chart has not already rendered var chart = $('#container').highcharts(options).highcharts();
Call
Highcharts.addEvent
to attach the event handler, as shown in the following code:Highcharts.addEvent(chart...