How to add Node data and Link data dynamically in GoJS?
Asked Answered
U

2

9
 myDiagram.model = new go.GraphLinksModel(
[

  { key: "Alpha", color: "lightblue" },
  { key: "Delta", color: "pink" }

],
[
  { from: "Alpha", to: "Alpha" },
  { from: "Delta", to: "Alpha" }
]);

I need to add more values dynamically, how should I do this?

Usually answered 15/2, 2015 at 11:4 Comment(1)
You need to check the API for GraphLinksModel to see how you add to it.Consternate
C
15

Node data (source: GoJS docs, class Model):

If you want to add or remove node data from the nodeDataArray, call the addNodeData or removeNodeData methods.

Link data (source: GoJS docs, class GraphLinksModel):

If you want to add or remove link data from the linkDataArray, call the addLinkData or removeLinkData methods. If you want to modify the node a link connects to, call the setFromKeyForLinkData and/or setToKeyForLinkData methods.

Chev answered 15/2, 2015 at 11:13 Comment(0)
O
0

An example of dynamically adding from an object list to a GraphLinksModel:

       var model = new go.GraphLinksModel();
        for(let id = 1; id < node_list.length; id++){
       model.addNodeData( { key: node_list[id].getNodeID(), color: "lightblue" } );
       model.addLinkData( { from: node_list[id].getPreviousNode(), to: node_list[id].getNodeID() } );
         }
       myDiagram.model = model;  
       console.log(model.nodeDataArray); //to see data
Ojibwa answered 6/11, 2019 at 23:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.