Highcharts 百分比堆叠区域图

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/chengqiuming/article/details/84962569

一 代码

<html>
<head>
<meta charset="UTF-8" />
<title>Highcharts 百分比堆叠区域图</title>
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="http://code.highcharts.com/highcharts.js"></script>
</head>
<body>
<div id="container" style="width: 550px; height: 400px; margin: 0 auto"></div>
<script language="JavaScript">
$(document).ready(function() {
   //图表类型为区域图
   var chart = {
      type: 'area'
   };
   //标题
   var title = {
      text: '按区域分列的世界人口增长的历史和估计'
   };
   var subtitle = {
      text: '世界范围'
   };
   //X 轴
   var xAxis = {
      categories: ['1750', '1800', '1850', '1900', '1950', '1999', '2050'],
      tickmarkPlacement: 'on',
      title: {
         enabled: false
      }
   };
   //Y 轴
   var yAxis = {
      title: {
         text: '十亿'
      },
      labels: {
         formatter: function () {
            return this.value / 1000;
         }
      }
   };
   var tooltip = {
      shared: true,
      valueSuffix: ' millions'
   };
   //数据点选项
   //置图表堆叠设置 plotOptions.area.stacking 为 "normal"。
   //如果禁用堆叠使用 null。 如果值为 "percent" 堆叠则按百分比。
   var plotOptions = {
      area: {
         stacking: 'percent',
         lineColor: '#666666',
         lineWidth: 1,
         marker: {
            lineWidth: 1,
            lineColor: '#666666'
         }
      }
   };
   var credits = {
      enabled: false
   };
   //数据
   var series= [{
       name: '亚洲',
            data: [502, 635, 809, 947, 1402, 3634, 5268]
        }, {
            name: '非洲',
            data: [106, 107, 111, 133, 221, 767, 1766]
        }, {
            name: '欧洲',
            data: [163, 203, 276, 408, 547, 729, 628]
        }, {
            name: '美洲',
            data: [18, 31, 54, 156, 339, 818, 1201]
        }, {
            name: '大洋洲',
            data: [2, 2, 2, 6, 13, 30, 46]
      }
   ];

   var json = {};
   json.chart = chart;
   json.title = title;
   json.subtitle = subtitle;
   json.xAxis = xAxis;
   json.yAxis = yAxis;
   json.tooltip = tooltip;
   json.plotOptions = plotOptions;
   json.credits = credits;
   json.series = series;
   $('#container').highcharts(json);

});
</script>
</body>
</html>

二 运行结果

猜你喜欢

转载自blog.csdn.net/chengqiuming/article/details/84962569