Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to modify highcharts legend item click event?

I need to modify click event on highcharts legend items. Highcharts demo http://www.highcharts.com/demo/line-basic . I want for example: first action will be some alert and second action will be action by default(clean Tokyo line from chart). Thanks. Sorry if question not clean.

like image 696
alexche8 Avatar asked May 15 '12 16:05

alexche8


1 Answers

You have to use the legendItemClick callback like the following code

plotOptions: {         line: {             events: {                 legendItemClick: function () {                    alert('I am an alert');                    //return false;                     // <== returning false will cancel the default action                     }                 }             ,             showInLegend: true         }     } 

Here is working fiddle which shows alert when you click on legends like on Tokyo and then hide Tokyo line.

See also the plotOptions documentation for the event in question. Where you need to place this may differ depending on what chart type you are using.

like image 179
Prasenjit Kumar Nag Avatar answered Sep 28 '22 16:09

Prasenjit Kumar Nag