当前位置:网站首页>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
}
}边栏推荐
- 一文读懂二十种开关电源拓扑结构
- Detailed description of iperf3 parameter options
- BaseQuickAdapter方法getBindingAdapterPosition
- MySQL [operator]
- conda 导出/导出配置好的虚拟环境
- 2022/07/29 Study Notes (day19) Exception Handling
- 积分简明笔记-第一类曲线积分的类型
- Unity performance analysis Unity Profile performance analysis tool
- 微软 SQL 服务器被黑,带宽遭到破坏
- 怎么在本地电脑上运行dist文件
猜你喜欢

【零基础玩转BLDC系列】以GD32F30x为例定时器相关功能详解

Golang DES 加解密如何实现?

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

Integral Topic Notes - Path Independent Conditions

The FPGA based protocol 2: the I2C read and write E squared PROM

MySQL Explain usage and parameter detailed explanation

MySQL Explain 使用及参数详解

剖析SGI STL空间配置器(空间配置器的重要性和重要成员及函数)

聊聊 MySQL 事务二阶段提交

Unreal Engine Graphic Notes: could not be compiled. Try rebuilding from source manually. Problem solving
随机推荐
2022 Hangzhou Electric Multi-School 2nd Game
MySQL [operator]
ant-design form表单校验upload组件(附个人封装的上传组件)
新手必备!最全电路基础知识讲解
剖析SGI STL空间配置器(_S_refill内存块填充函数)
【零基础玩转BLDC系列】以GD32F30x为例定时器相关功能详解
Unable to locate the program input point ucrtbase.abort on the dynamic link library api-ms-win-crt-runtime-|1-1-0.dll
How to run dist file on local computer
It is said that FPGA is high-end, what can it do?
[Yugong Series] July 2022 Go Teaching Course 021-Slicing Operation of Go Containers
积分简明笔记-第一类曲线积分的类型
XP电源维修fleXPower电源X7-2J2J2P-120018系列详解
利用R语言读取csv文件入一个数据框,然后查看各列的属性。
函数式接口&Lambda表达式——简单应用笔记
STM8L_库函数-模板搭建
els 方块停在方块上。
内卷下的智能投影行业,未来何去何从?
Is R&D moving to FAE (Field Application Engineer), is it moving away from technology?Is there a future?
[Fun BLDC series with zero basics] Taking GD32F30x as an example, the timer related functions are explained in detail
EMC过不了?都是PCB工程师的锅?