Highcharts 柱形图,线条图,饼图组合

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

一 代码

<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 title = {
      text: '组合图'
   };
   // X轴
   var xAxis = {
      categories: ['苹果', '橘子', '梨子', '香蕉', '李子']
   };
   // 标签
   var labels = {
      items: [{
         html: '水果消费',
            style: {
               left: '50px',
               top: '18px',
               color: (Highcharts.theme && Highcharts.theme.textColor) || 'black'
            }
      }]
   };
   // 数据
   var series= [{
        // 柱形图
        type: 'column',
            name: '小明',
            data: [3, 2, 1, 3, 4]
        }, {
            type: 'column',
            name: '小王',
            data: [2, 3, 5, 7, 6]
        }, {
            type: 'column',
            name: '小红',
            data: [4, 3, 3, 9, 0]
        }, {
            // 条形图
            type: 'spline',
            name: 'Average',
            data: [3, 2.67, 3, 6.33, 3.33],
            marker: {
                lineWidth: 2,
                lineColor: Highcharts.getOptions().colors[3],
                fillColor: 'white'
            }
        }, {
            // 饼图
            type: 'pie',
            name: '总消费',
            data: [{
                name: '小明',
                y: 13,
                color: Highcharts.getOptions().colors[0] // 小明 的颜色
            }, {
                name: '小王',
                y: 23,
                color: Highcharts.getOptions().colors[1] // 小王 的颜色
            }, {
                name: '小红',
                y: 19,
                color: Highcharts.getOptions().colors[2] // 小红 的颜色
            }],
            center: [100, 80],
            size: 100,
            showInLegend: false,
            dataLabels: {
                enabled: false
            }
      }
   ];     
      
   var json = {};   
   json.title = title;   
   json.xAxis = xAxis;
   json.labels = labels;  
   json.series = series;
   $('#container').highcharts(json);  
});
</script>
</body>
</html>

二 运行结果

猜你喜欢

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