其他配置请看我上一篇博客:
vue整合Echarts 实例PM2.5全国主要城市空气质量 百度地图
option值:
this.gaugeOption = {
tooltip: {
formatter: "{a} <br/>{b} : {c}%"
},
series: [
{
name: "业务指标",
type: "gauge",
detail: { formatter: "{value}%" },
data: [{ value: 50, name: "完成率" }]
}
]
};
写一个定时器
this.interval = setInterval(()=>{
this.gaugeOption.series[0].data[0].value = (Math.random() * 100).toFixed(2) - 0;
},2000);
},
深度监听option里面值的变化,只有变化,就从新setOption
watch: {
option: {
handler(val) {
this.chart.setOption(val);
},
deep: true
}
},
最后记得销毁定时器
beforeDestroy() {
clearInterval(this.interval);
},```