Youssef Mayoufi
Youssef Mayoufi

Reputation: 25

highcharts from event LegendItemClick to event textItemClick and iconItemClick

how to can change the code to add the event alert just by clicking the icon or symbol and remains the default event (visible and invisible chart ) just on the text of legend

plotOptions: {
        line: {

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

jsfiddle

Upvotes: 0

Views: 345

Answers (1)

Paweł Fus
Paweł Fus

Reputation: 45079

Compare target's:

        plotOptions: {
            line: {
                events: {
                    legendItemClick: function (event) {
                        var target = event.browserEvent.target;

                        if (target.tagName === "text") {
                            console.log("Text");   
                        } else {
                            console.log("Marker");
                        }
                    }
                },
                showInLegend: true
            }
        },

Demo: http://jsfiddle.net/LDMAQ/412/

Upvotes: 2

Related Questions