jquery和highcharts折線圖、直條圖、餅狀圖-類比後台傳參源碼

來源:互聯網
上載者:User

標籤: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折線圖、直條圖、餅狀圖-類比後台傳參源碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.