网络图节点关系节点合并->高图

时间:2019-02-06 15:37:44

标签: javascript jquery highcharts

我正在研究网络图图表 每个节点应该有一个新的子节点,但是如果它具有相同的名称(例如child1,child2,child3),则不应与另一个子节点合并,该子节点指向subchild1,对于每个个体,我们应该有指向每个节点的个体节点

提要链接-> https://jsfiddle.net/GnanaSagar/36k2wmry/1/
enter image description here

2 个答案:

答案 0 :(得分:2)

显然series.networkgraph.nodes有用。

series: [{
    dataLabels: {
      enabled: true
    },
    data: [
            {from: 'parent', to: 'child1'},
            {from: 'parent', to: 'child2'},
            {from: 'parent', to: 'child3'},
            {from: 'child1', to: 'subchild1.1'},
            {from: 'child2', to: 'subchild2.1'},
            {from: 'child3', to: 'subchild3.1'}
    ],
    nodes: [{
        id: 'subchild1.1',
        name: 'subchild1'
      },
      {
        id: 'subchild2.1',
        name: 'subchild1'
      },
      {
        id: 'subchild3.1',
        name: 'subchild1'
      }
    ]
  }]

jsFiddle:https://jsfiddle.net/9g42nqza/(我不得不注释掉一些原始代码,因为它抛出错误)。

答案 1 :(得分:1)

您还可以将formatter函数用于数据标签:

series: [{
    dataLabels: {
        enabled: true,
        format: undefined,
        formatter: function() {
            if (this.key.indexOf('subchild') >= 0) {
                return 'subchild1'
            }
            return this.key
        }
    },
    data: [...,
        {
            from: 'child1',
            to: 'subchild1'
        },
        {
            from: 'child2',
            to: 'subchild2'
        },
        {
            from: 'child3',
            to: 'subchild3'
        }
    ]
}]

实时演示:https://jsfiddle.net/BlackLabel/n4gd8v3r/

API:https://api.highcharts.com/highcharts/series.networkgraph.dataLabels.formatter