当前位置:网站首页>echart图表清空上一次数据
echart图表清空上一次数据
2022-07-30 08:50:00 【小猿L】
问题描述:
后台接口查询数据
图表然后渲染出来
再次查询想要用新的数据重新渲染图表
问题它来了:图表一直保留老数据!!!但是神奇的是可以叠加。已经重新setOption了还是不行,在这里卡了许久找bug,我真的傻。
解决!!!
清空图表数据-----将option里的series里的data和name都删除!!(有些代码可忽略)
clear () { // 清空上次echart数据
for (var i = 0; i < this.option.series.length; i++) { //置空关键!!! 清空名字和数据
this.option.series[i].data = []
this.option.series[i].name = ''
}
this.myGridBarChart = echarts.init(this.$refs.gridBarChartElem) //再次初始化
this.myGridBarChart.setOption(this.option, true) //重新setOption
this.legendList = [] //清空之前
this.dataList = [] //清空之前
},我这里是调用了图表组件,在这里用props接受后台查询的图表数据且用watch侦听变化,watch使用对象侦听形式,如下仅供参考 (option 为echart基本配置)
props:{
barData: {
type: Array,
default: () => {
return []
}
}
},
watch:{
'barData': {
handler (newVal) {
this.clear()
newVal.forEach((item, i) => {
this.legendList.push(item.card)
this.dataList.push(item.values)
})
this.option.yAxis[0].data = newVal[0].dates
this.legendList.forEach((item, index) => {
this.seriesData[index] = {
name: item,
type: 'bar',
stack: 'num',
emphasis: {
focus: 'series'
},
data: this.dataList[index]
}
})
this.option.series = this.seriesData
this.myGridBarChart.setOption(this.option) // 刷新图表
},
deep: true
}
}边栏推荐
猜你喜欢

一个低级错误导致的诡异现象——走近科学能拍三集,(C语言)最简单的数组元素读取,不正确!?

Unreal Engine Graphic Notes: could not be compiled. Try rebuilding from source manually. Problem solving

Kotlin value class - value class

Concise Notes on Integrals - Types of Curve Integrals of the Second Kind

公共Jar包的版本管理

硬件工程师

The difference between DDR, GDDR, QDR

Apache DolphinScheduler新一代分布式工作流任务调度平台实战-上

MySQL【运算符】

LeetCode二叉树系列——94.二叉树的中序遍历
随机推荐
Explain the problem of change exchange in simple terms - the shell of the backpack problem
MySQL中使用IN 不会走索引分析以及解决办法
C language classic practice questions (3) - "Hanoi Tower (Hanoi)"
浅论各种调试接口(JTAG、SWD、RDI、Jlink、Ulink、STlink)的区别
How to avoid CMDB becoming a data island?
宝塔搭建DM企业建站系统源码实测
硬件工程师
C# 之 $ – 字符串内插
新手必备!最全电路基础知识讲解
DDR、GDDR、QDR的区别
ClickHouse
2022杭电多校第一场
剖析SGI STL空间配置器(allocate内存分配函数)
Jetpack Compose 从入门到入门(八)
How to Assemble a Registry
内卷下的智能投影行业,未来何去何从?
树莓派_烧写Raspberry官方镜像系统
开关电源波纹的产生、测量及抑制,一篇全搞定!
统一异常处理导致ResponseBodyAdvice失效
20220728使用电脑上的蓝牙和汇承科技的蓝牙模块HC-05配对蓝牙串口传输