標籤:jquery highcharts
js代碼:
<script type="text/javascript"> $(function(){showLine();showColumn();showPie();});function showPie(){ jQuery.ajax({type: "get",url: "csylLine.json",async: false,dataType: "json",success:function(data1){$('#pieChart').highcharts({chart : {plotBackgroundColor : null,plotBorderWidth : null,plotShadow : false,type: 'pie'},title : { // 標題text : '城關區一周降雨地區佔全城份額比例'},tooltip : { // 提示框pointFormat : '{series.name}: <b>{point.percentage:.1f}%</b>'},plotOptions : {pie : {allowPointSelect : true,cursor : 'pointer',dataLabels : {enabled : false},showInLegend : true}},series : [ { // 資料列name : 'Browser share',data : data1.dataList} ], credits:{ // 著作權資訊 enabled:false }}); },error:function(err){alert(err);}}); }function showLine() {jQuery.ajax({type: "get",url: "csylLine.json",async: false,dataType: "json",success:function(data1){$('#lineChart').highcharts({ title: { text: '城關區一周內氣溫情況折線圖', x: -20 },//center標題 xAxis: { categories: data1.xList }, //橫座標資料點文字 yAxis: { title: { text: 'Temperature (°C)' //Y座標說明 }, plotLines: [{ value: 0, width: 1, color: '#808080' }] }, tooltip: { valueSuffix: '°C' }, legend: { borderWidth: 0 }, series: data1.yList, //此處定義兩個series,即兩條線,最高氣溫和最低氣溫,如果更多則在裡面添加大括弧。 credits: { // 著作權資訊 enabled: false } }); } });}function showColumn() {jQuery.ajax({type: "get",url: "csylLine.json",async: false,dataType: "json",success:function(data1){ $('#columnChart').highcharts({ chart: { type: 'column' //直條圖 }, title: { text: '城關區一周降雨預報' }, xAxis: { categories: data1.xList }, yAxis: { min: 0, title: { text: '%/mm' } }, tooltip: { pointFormat:'{series.name}: <b>{point.y} </b>', shared: true, useHTML: true }, plotOptions: { column: { pointPadding: 0.2, borderWidth: 0 } }, series: data1.zList, }); } });}</script>
後台傳參json格式:
{"xList":["09-10", "09-11", "09-12", "09-13", "09-14", "09-15", "09-16"],//x軸的資料(折線、柱形)"yList":[{ "name": "日最高溫","data": [28,28,27,26,29,32,25] }, { "name": "日最低溫","data": [15,15,14,13,16,19,12]}],"zList":[{ "name": "降雨幾率", "data": [16.0, 20.6, 48.5, 27.4, 19.1, 15.6, 0] },{ "name": "日降雨量", "data": [0.8, 0.5, 9.3, 1.0, 0.8, 0.6, 0] }],//折線圖和直條圖是一致的"dataList":[["城東",1],["平區",2],["東區",4],["西區",1],["郊區",1] ]//餅狀圖資料 }
jquery和highcharts折線圖、直條圖、餅狀圖-類比後台傳參源碼