1.optiono配置
leakLineOption: {
grid: {
left: '5%',
right: '5%',
top: '5%',
bottom: '0%'
},
tooltip: {
show: true,
trigger: 'axis'
},
xAxis: {
type: 'category',
axisLabel: {
interval: 0,
formatter: function(value, index) {
return toDateString(value, 'yyyy-MM-dd HH:mm')
}
},
data: []
},
yAxis: {
type: 'value',
max: 0.9,
min: 0,
splitNumber: 3,
axisLabel: {
show: true
},
nameTextStyle: {
color: 'white'
}
},
series: [
{
data: [],
type: 'line',
lineStyle: {
color: '#85a7ef'
},
symbol: 'none',
smooth: false
}
],
dataZoom: [
{
xAxisIndex: 0,
show: false,
type: 'slider',
startValue: 0,
endValue: 2,
orient: 'horizontal'
}
]
},
2.js代码
autoMove() {
this.timeOut = setInterval(() => {
if (
Number(this.leakLineOption.dataZoom[0].endValue) === this.pumpLength
) {
this.leakLineOption.dataZoom[0].endValue = 2
this.leakLineOption.dataZoom[0].startValue = 0
} else {
this.leakLineOption.dataZoom[0].endValue =
this.leakLineOption.dataZoom[0].endValue + 1
this.leakLineOption.dataZoom[0].startValue =
this.leakLineOption.dataZoom[0].startValue + 1
}
}, 3000)
}
3.获取数据
this.pumpLength = res.data.length
this.leakLineOption.xAxis.data = res.data.map(item => item.time)
this.leakLineOption.series[0].data = res.data.map(item => item.data)