Echarts:There is a chart instance already initialized on the dom!的解决办法

admin 阅读:133 2024-03-02

使用 Echarts 插件的时候,多次加载会出现 There is a chart instance already initialized on the dom! 错误,提示 echarts 已经初始化过了。

解决方法如下:

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

var myChart;

然后在具体的方法中先判断是否已经初始化过echarts实例:

//如果初始化过 echarts 实例,销毁。
if (myChart != null && myChart != "" && myChart != undefined){
    myChart.dispose();
}
// 基于准备好的 dom ,重新初始化 echarts 实例
myChart = echarts.init(document.getElementById('sjtjt'));
声明

1、部分文章来源于网络,仅作为参考。
2、如果网站中图片和文字侵犯了您的版权,请联系1943759704@qq.com处理!