首页 前端知识 Echarts控制台出现警告

Echarts控制台出现警告

2024-06-21 09:06:59 前端知识 前端哥 816 386 我要收藏

使用Echarts插件的时候,多次加载会出现[There is a chart instance already initialized on the dom.]的警告,意思是DOM上已经初始化了一个图表实例。

解决办法:

在使用Echarts插件的方法外面定义一个全局变量(注意:一定得是全局变量),然后在插件使用的方法内,添加判断,调用eChart.dispose()方法先将图表销毁,然后再初始化就不会出现警告了。

var rateChart;//全局变量
    function rate_fold(comPany, dataMon, nowSeries) {
        if (rateChart != null && rateChart != "" && rateChart != undefined) {
            rateChart.dispose();//销毁
        }
        rateChart = echarts.init(document.getElementById('rate_fold_line'));//初始化
        var option = {
            title: { text: "大用户成功率" }, tooltip: { trigger: 'axis' },
            legend: { data: comPany, orient: 'vertical', x: 'right', y: 'center' },
            calculable: true, xAxis: [{
                type: 'category', boundaryGap: false,
                data: dataMon, axisLabel: { rotate: 50 }
            }],
            yAxis: [{ type: 'value', max: 100, min: 98, splitNumber: 7 }],
            series: nowSeries
        };
        rateChart.setOption(option);
    }
转载请注明出处或者链接地址:https://www.qianduange.cn//article/13126.html
标签
评论
发布的文章

jQuery 选择器

2024-05-12 00:05:34

Vue中public/assets目录区别

2024-07-02 23:07:29

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!