Toggle navigation
动态数据 + 时间坐标轴
By
liujaygood
2017-09-01 07:40:59
脚本
16
21
作品使用的第三方脚本
数据管理
上传数据
支持小于 5M 任意格式(csv, xlsx, json, xml, ...)的数据文件
上传后可以通过生成的文件链接异步获取托管的数据。
历史数据
0 条
无历史数据
代码修改记录
信息提示
保存作品
对当前截图不满意?你还可以
上传本地截图
重新截图
作品名称
作品描述
标签
geo
grid
legend
markLine
markPoint
bar
effectScatter
line
lines
map
timeline
title
toolbox
tooltip
visualMap
作品默认版本
最新
16
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
20:11:45
图表已生成
整理代码
刷新
代码
//原文链接:http://blog.csdn.net/yin138/article/details/53730498 // 由于模拟数据较少,所以需要在图中滑动滚轮放大后才能看见效果 var data = []; var data1 = []; var anchor = [ { name: getToday() + ' 00:00:00', value: [ getToday() + ' 00:00:00', 0 ] }, { name: getTomorrow() + ' 00:00:00', value: [ getTomorrow() + ' 00:00:00', 0 ] } ]; option = { title: { text: '动态数据 + 时间坐标轴' }, tooltip: { trigger: 'axis', axisPointer: { animation: false } }, legend: { data: ['模拟数据', '模拟数据1'] }, xAxis: { type: 'time', splitLine: { show: false } }, yAxis: { type: 'value', boundaryGap: [0, '100%'], splitLine: { show: false } }, toolbox: { feature: { dataZoom: { yAxisIndex: 'none' }, restore: {}, saveAsImage: {} } }, dataZoom: [ { type: 'inside' } ], series: [{ name: '模拟数据', type: 'line', stack: '总量', smooth: true, areaStyle: {normal: {}}, showSymbol: false, hoverAnimation: false, data: data }, { name: '模拟数据1', type: 'line', stack: '总量', smooth: true, areaStyle: {normal: {}}, showSymbol: false, hoverAnimation: false, data: data1 },{ name: 'anchor', type: 'line', showSymbol: false, data: anchor, itemStyle: { normal: { opacity: 0 } }, lineStyle: { normal: { opacity: 0 } } }] }; function randomData() { data.push({ name: getToday() + ' ' + getSeconds(), value: [ getToday() + ' ' + getSeconds(), Math.round(Math.random() * 1002) ] }); data1.push({ name: getToday() + ' ' + getSeconds(), value: [ getToday() + ' ' + getSeconds(), Math.round(Math.random() * 32) ] }); } function getToday() { var now = new Date(); var year = now.getFullYear(); var month = now.getMonth() + 1; var date = now.getDate(); var hour = now.getHours(); if (hour < 10 && hour > 0) hour = '0' + hour; var minute = now.getMinutes(); if (minute < 10 && minute > 0) minute = '0' + minute; var seconds = now.getSeconds(); if (seconds < 10 && seconds > 0) seconds = '0' + seconds; return year + '/' + month + '/' + date; } function getTomorrow() { var now = new Date(); var oneday = 1000 * 3600 * 24; var tomorrow = new Date(+now + oneday); var year = tomorrow.getFullYear(); var month = tomorrow.getMonth() + 1; var date = tomorrow.getDate(); var hour = tomorrow.getHours(); if (hour < 10 && hour > 0) hour = '0' + hour; var minute = tomorrow.getMinutes(); if (minute < 10 && minute > 0) minute = '0' + minute; var seconds = tomorrow.getSeconds(); if (seconds < 10 && seconds > 0) seconds = '0' + seconds; return year + '/' + month + '/' + date; } function getSeconds() { var now = new Date(); var hour = now.getHours(); if (hour < 10) hour = '0' + hour; var minute = now.getMinutes(); if (minute < 10) minute = '0' + minute; var seconds = now.getSeconds(); if (seconds < 10) seconds = '0' + seconds; return hour + ':' + minute + ':' + seconds; } setInterval(function () { randomData(); console.log(data); myChart.setOption({ series: [ { data: data }, { data: data1 } ] }); }, 1000);