How to change the click event of a legend list item?

I need to change the click event on the elements of a high map legend. Highcharts demo version http://www.highcharts.com/demo/line-basic . For example, I want the first action to be some kind of warning, and the second action will act by default (a clean Tokyo line from the graph). Thank you Sorry if the question is not clean.

+49
javascript jquery highcharts
May 15 '12 at 16:22
source share
2 answers

You should use legendItemClick as 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 a working fiddle that shows a warning when you click on legends, like Tokyo, and then hide the Tokyo line.

See also the plotOptions documentation for this event. If you need to post this, this may vary depending on what type of chart you are using.

+66
May 15 '12 at 16:39
source share

For me, the legendItemClick event should have been for the series, not the line. For example:.

 plotOptions: { series: { events: { legendItemClick: function(event) { var visibility = this.visible ? 'visible' : 'hidden'; if (!confirm('The series is currently '+ visibility +'. Do you want to change that?')) { return false; } } } } }, 

Example from Highcharts: http://jsfiddle.net/gh/get/jquery/1.7.2/highslide-software/highcharts.com/tree/master/samples/highcharts/plotoptions/series-events-legenditemclick/

+9
Jul 29 '14 at 0:00
source share



All Articles