具有多个系列的树状图

Treemap with Multiple Series

我正在尝试创建包含多个系列的 TreeMap,该系列正在绘制在图表上,两个系列组合在一起,但我希望一次只显示一个系列。基本上可以使用 legand,但对于树图,它显示值。

这是jsfiddle I am trying to work on

JavaScript 使用的文件

<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/heatmap.js"></script>
<script src="https://code.highcharts.com/modules/treemap.js"></script>
<div id="container"></div>

树状图应根据所选系列进行更新。

Highchart 绑定使用

Highcharts.chart('container', {
    colorAxis: {
        minColor: '#FFFFFF',
        maxColor: Highcharts.getOptions().colors[0]
    },
    legend: {
        enabled: true,
    },
    series: [{
    name:"Series 1",
        stack: 'aeroplanes',
        type: 'treemap',
        layoutAlgorithm: 'squarified',
        data: [{
            name: 'A -Series 1',
            value: 6,
            colorValue: 1
        }, {
            name: 'B -Series 1',
            value: 6,
            colorValue: 2
        }, {
            name: 'C -Series 1',
            value: 4,
            colorValue: 3
        }, {
            name: 'D -Series 1',
            value: 3,
            colorValue: 4
        }, {
            name: 'E -Series 1',
            value: 2,
            colorValue: 5
        }, {
            name: 'F -Series 1',
            value: 2,
            colorValue: 6
        }, {
            name: 'G -Series 1',
            value: 1,
            colorValue: 7
        }]
    },
    // Second Series    
    {
       name:"Series 2",
        type: 'treemap',
        stack: 'aeroplanes2',
        layoutAlgorithm: 'squarified',
        visible:true,
        data: [{
            name: 'AA -Series 2',
            value: 16,
            colorValue: 2
        }, {
            name: 'BB -Series 2',
            value: 26,
            colorValue: 2
        }, {
            name: 'Cc -Series 2',
            value: 14,
            colorValue: 2
        }, {
            name: 'Dd -Series 2',
            value: 13,
            colorValue: 2
        }, {
            name: 'Ee -Series 2',
            value: 12,
            colorValue: 2
        }, {
            name: 'Ff -Series 2',
            value: 12,
            colorValue: 2
        }, {
            name: 'Gg -Series 2',
            value: 11,
            colorValue: 2
        }]
    }],
    title: {
        text: 'Highcharts Treemap'
    },
      plotOptions: {
      treemap: {
        stacking: 'percent'
      }
    },
});

默认情况下 showInLegend 等于树图系列的 false - 它需要手动启用。在 legendItemClick 事件中,我处理了系列可见性切换:

  plotOptions: {
    treemap: {
      showInLegend: true,
      events: {
        legendItemClick: function() {
          this.chart.series.forEach((s) => s.setVisible());
          return false;
        }
      }
    }
  }

现场演示: http://jsfiddle.net/kkulig/0n49vv74/


API 参考文献: