解决echarts echarts数据动态更新和dataZoom被重置问题
编程学习 2021-07-04 14:06www.dzhlxh.cn编程入门
这篇文章主要介绍了解决echarts echarts数据动态更新和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数据增量刷新还可以用appendData
补充知识:echarts动态添加数据
我就废话不多说了,大家还是直接看代码吧~
<template>
<!--为echarts准备一个具备大小的容器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: '动态数据 + 时间坐标轴'
},
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 : '模拟数据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 : '模拟数据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>
补充
主动使用echarts的resize方法改变图表大小:
(opts?: {
width?: number|string,
height?: number|string,
silent?: boolean
})
当在参数中填入宽高,this.echarts.resize({width:300}),dom层必须有一个初始化像素的宽高,百分比的宽高该方法不会生效。
以上这篇解决echarts echarts数据动态更新和dataZoom被重置问题就是长沙网络推广分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持狼蚁SEO。
编程语言
- ThinkPad 笔记本如何调节LCD屏幕亮度
- Dreamweaver制作网页打开特效教程
- Win10 Mobile 10586升级后无限重启怎么办 硬重启帮您
- Win8系统提示音频设备有问题有一个或多个音频服
- Xbox One版Win10首个预览版9月份发布
- 如何在textarea文本输入区内实现换行
- Win10 Build 9901系统更新 预览版新版本下载
- McAfee Framework存在远程格式串处理漏洞
- Win10家庭版今日(7月30)正式在中国官方商城开卖
- Win10 Mobile预览版更新完10536.1000后才收到10536.100
- Win10 RS2更新了什么-Win10 RS2最终版本号1704首曝
- Windows7如何查看回收站对应的文件夹有哪些方法
- Win10让Charms栏回归桌面的方法教程
- 取消Windows XP系统开机启动画面的小技巧
- win8系统怎么下载安装USB百兆网卡?
- XP系统下磁盘空间变少了怎么办?XP系统磁盘空间