There is a chart instance already initialized on the dom

使用Echarts插件的时候,多次加载会出现There is a chart instance already initialized on the dom.这个错误,改插件已经加载完成。

解决方法:

在方法最外层定义全局变量

var myChart;


然后在插件使用方法中:

 if (myChart != null && myChart != "" && myChart != undefined) {
	        myChart.dispose();
	    }
	// 基于准备好的dom,初始化echarts实例
     myChart = echarts.init(document.getElementById('sjtjt'));

方法的最开始写上判断,然后初始化echarts实例;

最重要的就是全局定义和方法开头的判断然后

myChart.dispose();

猜你喜欢

转载自blog.csdn.net/qq_31293575/article/details/81303796