从事件LegendItemClick到事件textItemClick和iconItemClick的高图

时间:2015-10-26 11:24:12

标签: javascript jquery highcharts

如何通过单击图标或符号来更改代码以添加事件警报,并且仅在图例文本上保留默认事件(可见和不可见图表)

plotOptions: {
        line: {

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

jsfiddle

1 个答案:

答案 0 :(得分:2)

比较target&#39; 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
            }
        },

演示:http://jsfiddle.net/LDMAQ/412/