首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >破坏顶图

破坏顶图
EN

Stack Overflow用户
提问于 2021-04-07 20:20:13
回答 1查看 658关注 0票数 0

我有两个职能:

首先是init图

代码语言:javascript
复制
function init(data, id) {
    let options = {
        series: data[1],
        chart: {
            width: 380,
            type: "donut"
        },
        labels: data[0],
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    position: "bottom"
                }
            }
        }],
        colors: [primary, success, warning, danger, info]
    };
    var chart = new ApexCharts(document.querySelector("#" + id), options);
    chart.render();
}

二是加载新图表。

代码语言:javascript
复制
function loadChart(data, id) {
    initChart(data, id);
}

用新数据(新系列和新标签)尝试init图表:

loadChart(data, 'chart_1');

loadChart(new_data, 'chart_1');

我怎么能从我的第一个洞穴中摧毁图表?

EN

回答 1

Stack Overflow用户

发布于 2022-02-24 16:27:18

代码语言:javascript
复制
function init(data, id) {
    if ( document.querySelector("#" + id).hasChildNodes() ) {
        document.querySelector("#" + id).innerHTML = '';
    }

    let options = {
        series: data[1],
        chart: {
            width: 380,
            type: "donut"
        },
        labels: data[0],
        responsive: [{
            breakpoint: 480,
            options: {
                chart: {
                    width: 200
                },
                legend: {
                    position: "bottom"
                }
            }
        }],
        colors: [primary, success, warning, danger, info]
    };

    var chart = new ApexCharts(document.querySelector("#" + id), options);
    chart.render();
}

我就是这么做的。我只是简单地检查了div是否有childNodes。如果是的话,我就把它清除了。简单而有效!只是在寻找另一个顶点图时遇到了这个问题。我想这不太常见。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66993596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档