简体   繁体   English

带有HighCharts的同一图表中的多个饼图

[英]Multiple pie-charts in the same chart with HighCharts

I'm trying to draw multiple pie-charts in the same chart with HighCharts . 我正在尝试使用HighCharts在同一张图表中绘制多个饼图。

JSFIDDLE DEMO

I have enabled the legend for each pie-chart. 我已为每个饼图启用了图例 Now two legends for the 2 charts are shown at the bottom ( notice that 2 items for each entry are visible in the legend ). 现在,底部显示了2个图表的两个图例注意,每个条目都有2个项目在图例中可见 )。 When I click on an item of the legend it shows/hides a piece in one pie-chart... 当我单击图例中的一个项目时,它会在一个饼图中显示/隐藏一个图块...

But I want to achieve either of followings, 但我想实现以下任何一项,

  1. I want to have a single legend for both charts so that relevant piece of both pie-charts disappears/appears when I click on an item of the legend . 我希望两个图表都具有一个图例 ,以便在单击图例项时,两个饼图的相关部分都消失/出现。

  2. I want to show only one legend and disable it so that clicking doesn't hide/show pieces of pie-charts. 我只想显示一个图例并禁用它,以使单击不会隐藏/显示饼图。

Anybody knows a way to achieve either? 有人知道一种实现方法吗?

Thank you in advance... 先感谢您...

I have added the below code to detect the legend item clicked. 我添加了以下代码来检测单击的图例项目。

function(chart) {
        $(chart.series[0].data).each(function(i, e) {
            e.legendItem.on('click', function(event) {
                var legendItem=e.name;

                event.stopPropagation();

                $(chart.series).each(function(j,f){
                       $(this.data).each(function(k,z){
                           if(z.name==legendItem)
                           {
                               if(z.visible)
                               {
                                   z.setVisible(false);
                               }
                               else
                               {
                                   z.setVisible(true);
                               }
                           }
                       });
                });

            });
        });
    }

Here is the jsfiddle 这是jsfiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM