解決echarts echarts數(shù)據(jù)動(dòng)態(tài)更新和dataZoom被重置問題
1.全局綁定滾輪事件,獲得dataZoom最新的位置:
myChart.on('dataZoom',function(event){
if(event.batch){
start=event.batch[0].start;
end=event.batch[0].end;
}else{
start=event.start;
end=event.end;
};
});
2.把最新的start和end賦值給要更新的option
window.setInterval(function () {
num=Math.random()*num+100;
data0.splice(0,1);
data0.push(num);
option.dataZoom[0].start=start;
option.dataZoom[0].end=end;
myChart.setOption(option);
},3000);
3.echart數(shù)據(jù)增量刷新還可以用appendData
補(bǔ)充知識(shí):echarts動(dòng)態(tài)添加數(shù)據(jù)
我就廢話不多說(shuō)了,大家還是直接看代碼吧~
<template>
<!--為echarts準(zhǔn)備一個(gè)具備大小的容器dom-->
<div id="main" style="width: 600px;height: 400px;"></div>
</template>
<script>
import echarts from 'echarts'
export default {
name: 'Chart',
data () {
return {
charts: '',
}
},
methods:{
initLine(id){
this.charts = echarts.init(document.getElementById(id))
this.charts.setOption({
title: {
text: '動(dòng)態(tài)數(shù)據(jù) + 時(shí)間坐標(biāo)軸'
},
tooltip: {
trigger: 'axis',
formatter: function (params) {
params = params[0]
return params.value[0] + ' : ' + params.value[1]
},
axisPointer: {
animation: false
}
},
xAxis: {
type: 'time',
splitLine: {
show: false
}
},
yAxis: {
type: 'value',
boundaryGap: [0, '100%'],
splitLine: {
show: false
}
},
animation: false
})
}
},
mounted(){
this.$nextTick(function() {
this.initLine('main')
this.charts.setOption({
series : [
{
name : '模擬數(shù)據(jù)0',
type : 'line',
showSymbol : false,
hoverAnimation : false,
data : [['2018-01-02', '3'],['2018-01-05', '4']]
}
]
})
setTimeout(() => {
this.charts.appendData({
seriesIndex:0,
data : [['2018-01-03', '1'],['2018-01-07', '2']]
})
},2000)
setTimeout(() => {
this.charts.resize();
},4000)
setTimeout(() => {
this.charts.setOption({
series : [
{},
{
name : '模擬數(shù)據(jù)1',
type : 'line',
showSymbol : false,
hoverAnimation : false,
data : [['2018-01-02', '5'],['2018-01-05', '10']]
}
]
})
this.charts.appendData({
seriesIndex:1,
data : [['2018-01-03', '11'],['2018-01-10', '2']]
})
},6000)
setTimeout(() => {
this.charts.resize();
},8000)
})
}
}
</script>
<style scoped>
* {
margin: 0;
padding: 0;
list-style: none;
}
</style>
補(bǔ)充
主動(dòng)使用echarts的resize方法改變圖表大小:
(opts?: {
width?: number|string,
height?: number|string,
silent?: boolean
})
當(dāng)在參數(shù)中填入寬高,this.echarts.resize({width:300}),dom層必須有一個(gè)初始化像素的寬高,百分比的寬高該方法不會(huì)生效。
以上這篇解決echarts echarts數(shù)據(jù)動(dòng)態(tài)更新和dataZoom被重置問題就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)ToDoList簡(jiǎn)單實(shí)例
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)ToDoList簡(jiǎn)單實(shí)例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-02-02
vue3接口數(shù)據(jù)賦值對(duì)象,渲染報(bào)錯(cuò)問題及解決
這篇文章主要介紹了vue3接口數(shù)據(jù)賦值對(duì)象,渲染報(bào)錯(cuò)問題及解決方案,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09
Vue中v-on的基礎(chǔ)用法、參數(shù)傳遞和修飾符的示例詳解
使用v-on:click給button綁定監(jiān)聽事件以及回調(diào)函數(shù),@是v-on:的縮寫,也就是簡(jiǎn)寫也可以使用@click,這篇文章主要介紹了Vue中v-on的基礎(chǔ)用法、參數(shù)傳遞和修飾符,需要的朋友可以參考下2022-08-08
Vue使用Axios和elementui實(shí)現(xiàn)查詢分頁(yè)功能
當(dāng)今的Web開發(fā)趨勢(shì)中,前后端分離已經(jīng)成為一種流行的架構(gòu)模式,它將前端和后端的開發(fā)分離開來(lái),使得前端和后端可以獨(dú)立進(jìn)行開發(fā)和部署,本文給大家介紹了Vue使用Axios和elementui實(shí)現(xiàn)查詢分頁(yè)功能,需要的朋友可以參考下2024-06-06
Vue toRef toRefs toRaw函數(shù)使用示例
這篇文章主要介紹了Vue toRef toRefs toRaw函數(shù)使用示例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧2023-03-03
VUE如何實(shí)現(xiàn)點(diǎn)擊文字添加顏色(動(dòng)態(tài)修改class)
這篇文章主要介紹了VUE如何實(shí)現(xiàn)點(diǎn)擊文字添加顏色(動(dòng)態(tài)修改class),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11

