echarts 折线图
Posted zhanglanzuopin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了echarts 折线图相关的知识,希望对你有一定的参考价值。
option = { title: { text: ‘动态数据‘, subtext: ‘纯属虚构‘ }, tooltip: { trigger: ‘axis‘, axisPointer: { type: ‘cross‘, label: { backgroundColor: ‘#283b56‘ } } }, legend: { // data:[‘最新成交价‘, ‘预购队列‘] // data:[‘最新成交价‘] data: [‘预购队列‘, ‘最新成交价‘, ‘联盟广告‘, ‘视频广告‘] }, toolbox: { show: true, feature: { dataView: {readOnly: false}, restore: {}, saveAsImage: {} } }, 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(10 - len - 1); } return res; })() } ], yAxis: [ { type: ‘category‘, scale: false, name: ‘价格‘, boundaryGap: [0.2, 0.2], data: [‘1M‘,‘2M‘,‘3M‘,‘4M‘,‘5M‘,‘6M‘] } , { type: ‘value‘, scale: true, name: ‘预购量111111‘, max: 1200, min: 0, boundaryGap: [0.2, 0.2] } ], series: [ { name: ‘预购队列‘, type: ‘line‘, xAxisIndex: 1, yAxisIndex: 1, // data: (function (){ // var res = []; // var len = 10; // while (len--) { // res.push(Math.round(Math.random() * 1000)); // } // return res; // })() data: [100, 250, 300, 450, 550, 600, 120, 530, 500, 500] } , // { // name: ‘最新成交价‘, // type: ‘line‘, // data: (function (){ // var res = []; // var len = 0; // while (len < 10) { // res.push((Math.random()*10 + 5).toFixed(1) - 0); // len++; // } // return res; // })() // }, { name: ‘联盟广告‘, type: ‘line‘, xAxisIndex: 1, yAxisIndex: 1, stack: ‘总量‘, data: [220, 182, 191, 234, 290, 330, 310, 200, 500, 700] }, { name: ‘视频广告‘, type: ‘line‘, xAxisIndex: 1, yAxisIndex: 1, stack: ‘总量‘, data: [150, 232, 201, 154, 190, 330, 410, 300, 500] }, ] }; app.count = 11; setInterval(function (){ var axisData = (new Date()).toLocaleTimeString().replace(/^D*/, ‘‘); var data0 = option.series[0].data; // var data1 = option.series[1].data; data0.shift(); data0.push(Math.round(Math.random() * 1000)); // data1.shift(); // data1.push((Math.random() * 10 + 5).toFixed(1) - 0); option.xAxis[0].data.shift(); option.xAxis[0].data.push(axisData); option.xAxis[1].data.shift(); option.xAxis[1].data.push(app.count++); myChart.setOption(option); }, 2100);
以上是关于echarts 折线图的主要内容,如果未能解决你的问题,请参考以下文章