1function orgEcharts(){ 2 var echartsData = [["年份"],["新训"],["复训"]]; 3 var dom = document.getElementById("container"); 4 var myChart = echarts.init(dom); 5 var app = {}; 6 $.ajax({ 7 url:'list/data.do', 8 data:{ 9 trainingunitId :$('#tree').val() 10 }, 11 type:'post', 12 dataType:'json', 13 success:function(data){ 14 for(var i=0;i<data.length;i++){ 15 echartsData[0].push(data[i].year); 16 echartsData[1].push(data[i].registerCount); 17 echartsData[2].push(data[i].driverRegisterCount); 18 } 19 option = null; 20 option = { 21 legend : {}, 22 tooltip : {}, 23 dataset : { 24 source : echartsData 25 }, 26 27 xAxis : [ { 28 type : 'category', 29 gridIndex : 0 30 }, { 31 type : 'category', 32 gridIndex : 1 33 } ], 34 yAxis : [ { 35 gridIndex : 0 36 }, { 37 gridIndex : 1 38 } ], 39 grid : [ { 40 bottom : '55%' 41 }, { 42 top : '55%' 43 } ], 44 series : [ 45 // These series are in the first grid. 46 { 47 type : 'bar', 48 seriesLayoutBy : 'row' 49 }, { 50 type : 'bar', 51 seriesLayoutBy : 'row' 52 }, 53 // These series are in the second grid. 54 { 55 type : 'bar', 56 xAxisIndex : 1, 57 yAxisIndex : 1 58 }, { 59 type : 'bar', 60 xAxisIndex : 1, 61 yAxisIndex : 1 62 }, { 63 type : 'bar', 64 xAxisIndex : 1, 65 yAxisIndex : 1 66 } ], 67 label : { 68 show : true, 69 position : 'top' 70 } 71 }; 72 ; 73 if (option && typeof option === "object") { 74 myChart.setOption(option, true); 75 } 76 } 77 78 }); 79} 80
先设置了一个数组 echartsData,ajax请求吧数据导入到数据,然后赋值给dataset.source,实现数据赋予 运行orgEcharts()方法,重新请求数据,如果数据改变,就刷新图像