首页 > 解决方案 > 网络图 - 有没有办法在点击网络图中隐藏特定节点?

问题描述

我试图在网络图中单击时隐藏一个节点。如何使用 highcharts 在网络图中隐藏节点?

我已经尝试删除系列中的节点并更新图表。有没有更好的办法?

网络图

标签: javascripthighcharts

解决方案


click要隐藏事件使用remove方法上的特定点:

plotOptions: {
    networkgraph: {
        ...,
        point: {
            events: {
                click: function() {
                    this.remove();
                }
            }
        }
    }
}

但是,networkgraph图表中存在与remove方法相关的错误(此处报告:https ://github.com/highcharts/highcharts/issues/10565 ),因此您还需要使用解决方法:

Highcharts.wrap(
    Highcharts.seriesTypes.networkgraph.prototype, 'generatePoints',
    function(p) {
        if (this.nodes) {
            this.nodes.forEach(function(node) {
                node.destroy();
            });
            this.nodes.length = 0;
        }
        return p.apply(this, Array.prototype.slice.call(arguments, 1));
    }
);

现场演示: https ://jsfiddle.net/BlackLabel/m9tjb481/

API 参考: https ://api.highcharts.com/class-reference/Highcharts.Point#remove


推荐阅读