Highcharts 柱形圖,線條圖,餅圖組合
阿新 • • 發佈:2018-12-30
一 程式碼
<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>
二 執行結果