Search code examples
javascriptamchartsamcharts4knowledge-graph

Add several links between two nodes in amcharts force directed network


I'm using amcharts force directed network to render a knowledge graph. In this knowledge graph two nodes can have multiple edges in each direction.

For example:

A "person" can be "born in" a city.

Also,

A "person" can "live in" a city.

From reading the documentation, I can make links between the edges using "linkWith", but I can't add a "type" and add more links.

Example of two nodes with two link types

Here is a sample of the json file:

{
  "id": "200",
  "type": "City",
  "name": "New York",
  "color": "#2CB186",
  "linkWith": [{
    "115": ["born_in", "lives_in"]
  }]
}


Solution

  • If you want

                    _label:lives_               
                   /             \
      (node:'John')               (node:'New York')
                   \__label:born_/
    

    It isn't capable of that. no parrallel relationships between two nodes the best you can do is make the labels into nodes and connect them like this.

                   __(node:'lives')_
                  /                 \
     (node:'John')                   (node:'New York')
                  \__(Node:'Born')__/
    

    I know its likely not ideal, also maybe look into https://www.amcharts.com/demos/transport-metro-map/ you can build relationships with multiple line segments between the same node.