今天在完成项目的时候遇到了后台数据更新,但是echart的图表却不更新,这时可以在setoption里面添加true,ECharts 中实现异步数据的更新,在图表初始化后不管任何时候只要通过 jQuery 等工具异步获取数据后通过 setOption 填入数据和配置项就行。
echarts.init(document.getElementById('main')).setOption({
xAxis: {
type: 'category',
// x轴
data: data.abscissa,
boundaryGap: [0, 3],
axisTick: {
show: false
}
},
grid: {
left: 0,
right: 10,
bottom: 30,
top: 30,
containLabel: true
},
tooltip: {
trigger: 'axis',
axisPointer: {
// type: "cross",
},
padding: [5, 10]
},
yAxis: {
// name: this.title,
type: 'value',
max: function(value) {
return value.max + 5
},
axisLine: {
show: false // 不显示坐标轴轴线
},
axisTick: {
show: false // 不显示坐标轴刻度
},
splitLine: {
show: true,
lineStyle: {
type: 'dashed'
}
}
},
series: this.temp
}, true)