Highcharts - 不同等级树状图

以下实例使用不同颜色来标识不同等级的树状图。

我们在前面的章节已经了解了 Highcharts 基本配置语法。接下来让我们来看下其他的配置。

配置

series.type 配置

设置 series 的 type 属性为 treemap ,series.type 描述了数据列类型。默认值为 "line"。

var series = {
   type: 'treemap'
};

示例

文件名:highcharts_tree_levels.htm

<html>
   <head>
      <title>Highcharts 教程</title>
      <script src = "https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
      <script src = "https://code.highcharts.com/highcharts.js"></script>    
      <script src = "https://code.highcharts.com/modules/treemap.js"></script>    
      <script src = "https://code.highcharts.com/modules/heatmap.js"></script>  
   </head>
   
   <body>
      <div id = "container" style = "width: 550px; height: 400px; margin: 0 auto"></div>
      <script language = "JavaScript">
         $(document).ready(function() {    
            var title = {
               text: 'Fruit consumption'   
            };
            var series = [{
               type: "treemap",
               layoutAlgorithm: 'stripes',
               alternateStartingDirection: true,
               
               levels: [{
                  level: 1,
                  layoutAlgorithm: 'sliceAndDice',
                  dataLabels: {
                     enabled: true,
                     align: 'left',
                     verticalAlign: 'top',
                     style: {
                        fontSize: '15px',
                        fontWeight: 'bold'
                     }
                  }
               }],
               data: [
                  {
                     id: 'A',
                     name: 'Apples',
                     color: "#EC2500"
                  }, 
                  {
                     id:'B',
                     name: 'Bananas',
                     color: "#ECE100"
                  }, 
                  {
                     id: 'O',
                     name: 'Oranges',
                     color: '#EC9800'
                  }, 
                  {
                     name: 'Anne',
                     parent: 'A',
                     value: 5
                  }, 
                  {
                     name: 'Rick',
                     parent: 'A',
                     value: 3
                  }, 
                  {
                     name: 'Peter',
                     parent: 'A',
                     value: 4
                  }, 
                  {
                     name: 'Anne',
                     parent: 'B',
                     value: 4
                  }, 
                  {
                     name: 'Rick',
                     parent: 'B',
                     value: 10
                  }, 
                  {
                     name: 'Peter',
                     parent: 'B',
                     value: 1
                  }, 
                  {
                     name: 'Anne',
                     parent: 'O',
                     value: 1
                  }, 
                  {
                     name: 'Rick',
                     parent: 'O',
                     value: 3
                  }, 
                  {
                     name: 'Peter',
                     parent: 'O',
                     value: 3
                  }, 
                  {
                     name: 'Susanne',
                     parent: 'Kiwi',
                     value: 2,
                     color: '#9EDE00'
                  }
               ]
            }];
      
            var json = {};     
            json.title = title;            
            json.series = series;       
   
            $('#container').highcharts(json);
         });
      </script>
   </body>
   
</html>

以上图表实例的输出结果

❮ highcharts_tree_maps.html