There is a chart instance already initialized on the dom
当页面刷新或多次加载echarts实例时,控制台会出现There is a chart instance already initialized on the dom警告,表示该DOM实例已经被加载。
有看到网上许多解决方法,都是先定义出echarts实例,使用时判断该实例是否已被加载,虽然可以解决,但实例过多时就需要定义许多相对来说就比较麻烦。下面的这个方法就比较简单,不需要提前定义实例。
// 检测是否已经存在echarts实例,如果不存在,则不再去初始化
let myEnergyTrenChart = echarts.getInstanceByDom(document.getElementById("tendency_chart"))
if (myEnergyTrenChart == null) {
myEnergyTrenChart = echarts.init(document.getElementById('tendency_chart'));
}