在做关于echarts项目时常常会遇到,套用组件时,明明拿到了数据,图表数据效果却渲染不出来的情况。
在检查有关数据设置没问题之后,我们可以用watch监听对应的获取数据,开启deep和immediate后,将原option中的相关设置复制过来再次赋值,给与到对应的option中的data,lable或其他设置项中,以保证图表能重新渲染
watch: {
'sumPlanAmount':{
handler(newvalue,oldvalue){
this.$nextTick(() => {
const label={
color:'#BD3B04',
insideColor:'#fff',
formatter: '{a|滞后率}'+'\n\r' + '{b|'+this.lagRate +' }' +'{x|%}',
rich: {
a: {
fontFamily: 'PingFang SC',
fontSize: 16,
fontWeight: 400,
lineHeight: 13,
textAlign: 'center',
},
b: {
fontFamily: 'Helvetica Neue',
letterSpacing:0,
fontSize:19.52,
fontWeight: 500,
textAlign:'center',
lineHeight: 24.4
},
x: {
fontFamily: 'Helvetica Neue',
fontWeight: 400,
lineHeight:17.08,
letterSpacing:0,
textAlign:'center',
fontSize:10,
},
}
}
const data= [this.lagRate/100,this.lagRate/100]
this.$set(this.option100.series[0],'label',label)
this.$set(this.option100.series[0],'data',data)
var myChart10 = echarts.init(this.$refs.myChart10);
this.option100 && myChart10.setOption(this.option100,true);
})
},
immediate: true,
deep: true,
},
},