简体   繁体   English

将连接图例用于两个Highcharts饼图

[英]Using connecting legends for two Highcharts pie charts

I have several pie chart series with the same names but different values. 我有几个饼图系列,它们的名称相同但值不同。 I want to be able to toggle wedges with the same name in all series on and off by clicking in the legend. 我希望能够通过单击图例来打开和关闭所有系列中具有相同名称的楔子。

The documentation and several other questions suggest using series.linkedTo to connect the series, but I can't get it to work. 文档和其他一些问题建议使用series.linkedTo来连接系列,但是我无法使其正常工作。

This is what I've tried building on a Highcharts example: 这是我尝试在Highcharts示例中构建的内容:

series: [{
        center: ['25%', '50%'],
    showInLegend: true,
    id: 'aaa',
    data: [
        ['Firefox',   44.2],
        ['IE7',       26.6],
        ['IE6',       20],
        ['Chrome',    3.1],
        ['Other',    5.4]
    ]
},
{
        id: 'bbb',
        linkedTo: 'aaa',
        center: ['75%', '50%'],
    data: [
        ['Firefox',   12.52],
        ['IE7',       12.83],
        ['IE6',       0],
        ['Chrome',    59.42],
        ['Other',    5.4]
    ]
}]

Here's the fiddle with full (non-working) code: http://jsfiddle.net/JanSoderback/psL0zy2g/22/ 这是带有完整(无效)代码的小提琴: http : //jsfiddle.net/JanSoderback/psL0zy2g/22/

Using linkedTo does not work, because it is not the series that you want to hide/show (as with 2 lines series) but each point of the series. 使用linkedTo不起作用,因为它不是要隐藏/显示的序列(与2行序列一样),而是序列的每个点。

What you can do however, is change what clicking on the legend will do, like this: 但是,您可以做的就是更改单击图例的操作,如下所示:

plotOptions: {
  pie: {
    point: {
      events: {
        legendItemClick: function() {
          for (var i = 0; i < chart.series.length; i++) {
            if (chart.series[i].points[this.index].visible == true) {
              chart.series[i].points[this.index].setVisible(false, false);
            } else {
              chart.series[i].points[this.index].setVisible(true, false);
            }
          }
          chart.redraw();
          return false; //needed to stop the normal click from interferring
        }
      }
    }
  }
...
},

Note that this example will only work if both pies contain an identical number of points, sorted in the same order. 请注意,只有两个派都包含相同数量的点(以相同顺序排序)时,此示例才有效。 If that is not the case, you can expand on this. 如果不是这种情况,则可以对此进行扩展。

Working example: http://jsfiddle.net/ewolden/psL0zy2g/63/ 工作示例: http : //jsfiddle.net/ewolden/psL0zy2g/63/

API on event.legendItemClick: https://api.highcharts.com/highcharts/series.pie.events.legendItemClick event.legendItemClick上的API: https ://api.highcharts.com/highcharts/series.pie.events.legendItemClick

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

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