Add Edge Dynamically visjs

Dinesh K picture Dinesh K · Sep 26, 2016 · Viewed 9.8k times · Source

Can anyone help me with adding edges dynamically in this visjs network? Actually, I am trying to use drag and drop to add nodes to the canvas, but I need help adding edges when I click the node and add edge dynamically to another node existing on canvas.

Answer

pgoldweic picture pgoldweic · Sep 27, 2016

You can use the vis.js 'update' function to add either nodes or edges dinamycally. You simply pass in an array with the set of either nodes or edges that you are trying to add. You call it like this:

nodes.update(updateNodesArray)

OR

edges.update(updateEdgesArray)

where nodes and edges are the vis.DataSet instances that you originally created for the network.

Full docs can be found at http://visjs.org/docs/data/dataset.html