解决办法,在重新渲染之前,先给他清空在渲染
echarts.init(document.getElementById('main')).dispose();
var myChart = echarts.init(document.getElementById('main'), buttonS);
function fun(n) {
if (n == 1) {
fun1('walden')
fun2('walden')
} else if (n == 2) {
fun1('dark')
fun2('dark')
}
}
// 基于准备好的dom,初始化echarts实例
function fun1(buttonS) {
echarts.init(document.getElementById('main')).dispose();
var myChart = echarts.init(document.getElementById('main'), buttonS);
// 指定图表的配置项和数据
var option = {
title: {
text: 'Rainfall and Flow Relationship',
left: 'center'
},
grid: {
bottom: 80
},
toolbox: {
feature: {
dataZoom: {
yAxisIndex: 'none'
},
restore: {},
saveAsImage: {}
}
},
tooltip: {
trigger: 'axis',
axisPointer: {
type: 'cross',
animation: false,
label: {
backgroundColor: '#505765'
}
}
},
legend: {
data: ['Flow', 'Rainfall'],
left: 10
},
dataZoom: [
{
show: true,
realtime: true,
start: 65,
end: 85
},
{
type: 'inside',
realtime: true,
start: 65,
end: 85
}
],
xAxis: [
{
type: 'category',
boundaryGap: false,
axisLine: { onZero: false },
// prettier-ignore
data: [
]
}
]
};
// 使用刚指定的配置项和数据显示图表。
myChart.setOption(option);
}