当前位置:网站首页>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
}
}边栏推荐
- DDR、GDDR、QDR的区别
- 硬件工程师
- Access to display the data
- HashSet和LinkedHashSet
- 【HMS core】【FAQ】HMS Toolkit典型问题合集1
- 企业数字化建设,自研还是采购?
- Activating data potential Amazon cloud technology reshapes cloud storage "family bucket"
- ant-design form form verification upload component (with personal packaged upload component)
- 20220728 Use the bluetooth on the computer and the bluetooth module HC-05 of Huicheng Technology to pair the bluetooth serial port transmission
- XP电源维修fleXPower电源X7-2J2J2P-120018系列详解
猜你喜欢

怎么在本地电脑上运行dist文件

MySQL之COUNT性能到底如何?

电路分析:运放和三极管组成的恒流源电路

Field interpretation under "Surgical variables (RX SUMM-SURG OTH REG/DIS)" in SEER database

20220728使用电脑上的蓝牙和汇承科技的蓝牙模块HC-05配对蓝牙串口传输

一文读懂二十种开关电源拓扑结构

仿牛客网项目第一章:开发社区首页(详细步骤和思路)

【 HMS core 】 【 】 the FAQ HMS Toolkit collection of typical questions 1

Integral Topic Notes - Path Independent Conditions

自动化测试selenium(一)
随机推荐
Using IN in MySQL will not go through index analysis and solutions
leetcode-990:等式方程的可满足性
PyQt5快速开发与实战 7.4 事件处理机制入门 and 7.5 窗口数据传递
20个电路能懂5个以上,足以证明你在电子行业混过!
PyQt5快速开发与实战 8.1 窗口风格
ACL 2022 | 引入角度margin构建对比学习目标,增强文本语义判别能力
MySQL数据库题库
The difference between DDR, GDDR, QDR
剑指offer 48:最长不重复子串
XP电源维修fleXPower电源X7-2J2J2P-120018系列详解
Integral Special Notes-Three Formulas for Curve Area Integral
涛思 TDengine 2.6+优化参数
Functional Interfaces & Lambda Expressions - Simple Application Notes
Windows 下安装 MySQL
延迟队列MQ
els 方块向左移动
C# 之 $ – 字符串内插
【无标题】
编程界的“躲猫猫”比赛 | 每日趣闻
Kotlin 值类 - value class