1. 程式人生 > >echart折線圖 柱形圖 資料格式化 動態繫結資料 frame處理

echart折線圖 柱形圖 資料格式化 動態繫結資料 frame處理

var myChart; var eCharts; require.config({ paths : { 'echarts' : '${pageContext.request.contextPath}/路徑', 'echarts/chart/line' : '${pageContext.request.contextPath}/路徑' } }); require
([ 'echarts', 'echarts/chart/line' ], DrawEChart //非同步載入的回撥函式繪製圖表 ); //建立ECharts圖表方法 function DrawEChart(ec) { eCharts = ec; myChart = eCharts.init(document.getElementById('main')); //定義圖表options var options = { title : { text : "次數"
, subtext : "純屬虛構", sublink : "http://www.baidu.com" }, tooltip : { trigger : 'axis' }, legend : { data : [] }, toolbox : { show : true
, feature : { mark : { show : true }, dataView : { show : true, readOnly : false }, magicType : { show : true, type : [ 'line', 'bar' ] }, restore : { show : true }, saveAsImage : { show : true } } }, calculable : true, xAxis : [ { show : true, type : 'category', boundaryGap : false, data : [] } ], yAxis : [ { type : 'value', show : true, splitArea : { show : true } } ], grid : { width : '90%' }, series : [ { show : true, name : '次數', type : 'bar', data : [], //系列中的資料標註內容 markPoint : { data : [ { type : 'max', name : '最大值' }, { type : 'min', name : '最小值' } ] } } ], }; myChart.hideLoading(); myChart.setOption(options); //先把可選項注入myChart中 getChartData();//ajax後臺互動 window.onresize = myChart.resize; }; function getChartData() { //獲得圖表的options物件 var options = myChart.getOption(); //通過Ajax獲取資料 $.ajax({ type : "post", async : false, //同步執行 url : "${pageContext.request.contextPath}/frontUser/login/list_data.do", dataType : "json", //返回資料形式為json success : function(result) { /* console.log(result); */ if (result) { options.legend.data = result[0].legend; options.xAxis[0].data = result[0].category; options.series[0].data = result[0].series; myChart.hideLoading(); myChart.setOption(options); } }, error : function(errorMsg) { alert("圖表請求資料失敗"); myChart.hideLoading(); } }); }