HTML:
<script> var cx=[]; $(document).ready(function () { $.ajax({ type : "get", url : ctx + "/admin/zklt/payInfo/getZKLTSjjlYangLao_CanBaoLvList", dataType: "json", success : function(result) { for(var i =0;i<result.length;i++){ cx.push(result[i]); } myChart1.hideLoading(); myChart1.setOption({ series:[{ data:cx }] }); }, error:function(){ alert("error"); } }); }); </script> <div id="chart1"></div> <script src="#(ctx)/common/plugins/echart/echarts.min.js"></script> <script> var myChart1 = echarts.init(document.getElementById('chart1')); var option1 = { tooltip: { trigger: 'item', formatter: "{a} <br/>{b} : {c} ({d}%)" }, legend: { orient: 'vertical', left: 'left', data: ['五保', '扶貧'] }, series: [ { name: '通路來源', type: 'pie', radius: '55%', center: ['50%', '50%'], data: [ { value: 335, name: '五保' }, { value: 310, name: '扶貧' }], itemStyle: { emphasis: { shadowBlur: 10, shadowOffsetX: 0, shadowColor: 'rgba(0, 0, 0, 0.5)' } } } ] }; myChart1.setOption(option1); |
切記:從背景擷取的資料必須是json格式