Trigger a click event on a legend item in Highchart

Sometimes you have a few series in your chart and you want to turn off some of them, maybe because they are too big thus skewing the rest of the data. See below for example, the green bar is just too long compared to the other two.

highchart_bar_legend_on

We know that mouse-clicking on a legend item can turn series on and off. Here after clicking on the green legend item, we see:

highchart_bar_legend_off

To do that programmatically, here is how you do it.


var chart;
$(document).ready(function() {
  chart = new Highcharts.Chart({
    // blah blah blah...
  });

  // auto click on the 3rd legend label to disable that series from showing up
  $(chart.series[2].legendItem.element).trigger('click');
});

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s