legendItemClick-highchart的饼图 - 自定义事件 [英] Pie chart -custom event for legendItemClick-highchart

查看:199
本文介绍了legendItemClick-highchart的饼图 - 自定义事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请查看jsfiddle here 了解我的意图。
要获得 legendItemClick 工作,我需要点击图例中的彩色按钮。



但是在这个示例中,即使点击文本(彩色按钮的右侧)也会触发 legendItemClick 点击事件。



即使当我点击文字时,我应该怎么做才能使事件发生?

解决方案

根据文档legendItemClick在饼图中不受支持 http: //api.highcharts.com/highcharts#plotOptions.pie.events.legendItemClick ,但是您可以使用以下解决方法: http://jsfiddle.net/JkDrM/13/

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


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?

解决方案

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);
        });
    });

这篇关于legendItemClick-highchart的饼图 - 自定义事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆