Pie chart -custom event for legendItemClick-highch

2019-08-23 02:26发布

问题:

Please have a look at the jsfiddle here to understand what I am upto. To get the legendItemClick working I need to click on the colored buttons in the legend.

But in this sample even clicking on the texts(right to the colored buttons) fires legendItemClick click event.

what should I do to get the event fired even when I click on the text?

回答1:

According to documentation legendItemClick is not supported in pie chart http://api.highcharts.com/highcharts#plotOptions.pie.events.legendItemClick but you can use workaround: http://jsfiddle.net/JkDrM/13/

    $(chart.series[0].data).each(function(i, e) {
        e.legendItem.on('click', function() {
            if (!e.sliced) {
                alert('hide slice');
            } else {
                alert('show slice');
            }
            e.slice(!e.sliced);
        });
    });


回答2:

I guess you have not framed your question correctly! "// some code here to achieve my goal" what goal?