getTransformerSubstation3 () {
// this.myChart3.clear()
this.myChart3 = this.$echarts.init(document.getElementById('oneChart3'))
api
.getTransformerSubstation3(this.bdzparams)
.then(data => {
this.transformerSubstationList3 = data
let option = {
yAxis: {
type: 'category',
data: this.transformerSubstationList3.data.Asix,
},
xAxis: {
type: 'value',
},
series: [
{
data: this.transformerSubstationList3.data.data0,
type: 'bar',
itemStyle: {
normal: {
color: '#32b16c',
label: {
show: true,
position: 'right',
textStyle: {
color: 'black',
fontSize: 10,
},
},
},
},
barWidth: 20,
},
],
grid: {
x: '3%',
y: '20%',
bottom: '3%',
containLabel: true,
},
},
},
}
this.myChart3.setOption(option)
})
},
vue中使用echarts,数据更新后无法重新绘制图表?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
关注 引用 皆我百晓生 小程序回复内容作答:
在Vue中使用echarts时,如果想要更新数据后重新绘制图表,可以先调用clear
方法清空已有图表,并重新初始化myChart3
。下面是修改后的代码:
getTransformerSubstation3() { if (this.myChart3) { this.myChart3.clear(); } this.myChart3 = this.$echarts.init(document.getElementById('oneChart3')); api.getTransformerSubstation3(this.bdzparams).then((data) => { this.transformerSubstationList3 = data; let option = { yAxis: { type: 'category', data: this.transformerSubstationList3.data.Asix, }, xAxis: { type: 'value', }, series: [ { data: this.transformerSubstationList3.data.data0, type: 'bar', itemStyle: { normal: { color: '#32b16c', label: { show: true, position: 'right', textStyle: { color: 'black', fontSize: 10, }, }, }, }, barWidth: 20, }, ], grid: { x: '3%', y: '20%', bottom: '3%', containLabel: true, }, }; this.myChart3.setOption(option); }); },
在每次更新数据之前,先判断
myChart3
是否存在,如果存在则调用clear
方法清空已有图表。然后重新初始化myChart3
并设置新的数据和配置项,最后调用setOption
方法重新绘制图表。这样就可以实现数据更新后重新绘制图表了。解决 无用评论 打赏 举报
悬赏问题
- ¥15 剑网三内存脚本有没有作者可以做
- ¥15 c#转安卓 java html
- ¥15 os.listdir文件路径找不到
- ¥15 使用gojs3.0,如何在nodeDataArray设置好text的位置,再go.TextBlock alignment中进行相应的改变
- ¥15 psfusion图像融合指标很低
- ¥15 银河麒麟linux系统如何修改/etc/hosts权限为777
- ¥50 医院HIS系统代码、逻辑学习
- ¥30 docker离线安装mysql报错,如何解决?
- ¥15 构建工单的总账影响在哪里查询或修改
- ¥15 三个简单项目写完之后有重赏之后联系我