多系列树形图

时间:2018-01-09 13:46:59

标签: highcharts treemap

我正在尝试创建具有多个系列的TreeMap,该系列将在图表上绘制,两个系列都聚集在一起,但我希望一次只显示一个系列。基本上可以使用legand,但是对于树形图,它显示了值。

我正在jsfiddle

尝试enter image description here

使用的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'
      }
    },
});

1 个答案:

答案 0 :(得分:2)

对于treemap系列,

默认情况下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参考: