option
option = { title : { text: '動態數據', subtext: '純屬虛構' }, 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} } }, dataZoom : { show : false, start : 0, end : 100 }, xAxis : [ { type : 'category', boundaryGap : true, data : (function (){ var now = new Date(); var res = []; var len = 10; while (len--) { res.unshift(now.toLocaleTimeString().replace(/^\D*/,'')); now = new Date(now - 2000); } return res; })() }, { type : 'category', boundaryGap : true, data : (function (){ var res = []; var len = 10; while (len--) { res.push(len + 1); } return res; })() } ], yAxis : [ { type : 'value', scale: true, name : '價格', boundaryGap: [0.2, 0.2] }, { type : 'value', scale: true, name : '預購量', boundaryGap: [0.2, 0.2] } ], series : [ { name:'預購隊列', type:'bar', xAxisIndex: 1, yAxisIndex: 1, data:(function (){ var res = []; var len = 10; while (len--) { res.push(Math.round(Math.random() * 1000)); } return res; })() }, { name:'最新成交價', type:'line', data:(function (){ var res = []; var len = 10; while (len--) { res.push((Math.random()*10 + 5).toFixed(1) - 0); } return res; })() } ] }; var lastData = 11; var axisData; clearInterval(timeTicket); timeTicket = setInterval(function (){ lastData += Math.random() * ((Math.round(Math.random() * 10) % 2) == 0 ? 1 : -1); lastData = lastData.toFixed(1) - 0; axisData = (new Date()).toLocaleTimeString().replace(/^\D*/,''); // 動態數據接口 addData myChart.addData([ [ 0, // 系列索引 Math.round(Math.random() * 1000), // 新增數據 true, // 新增數據是否從隊列頭部插入 false // 是否增加隊列長度,false則自定刪除原有數據,隊頭插入刪隊尾,隊尾插入刪隊頭 ], [ 1, // 系列索引 lastData, // 新增數據 false, // 新增數據是否從隊列頭部插入 false, // 是否增加隊列長度,false則自定刪除原有數據,隊頭插入刪隊尾,隊尾插入刪隊頭 axisData // 坐標軸標籤 ] ]); }, 2100);
刷 新
切換主題