Vis.js: Modify node properties on click

manglano picture manglano · Sep 24, 2015 · Viewed 9.1k times · Source

I have an undirected graph in Vis.js and I would like to change the color and size of the adjacent nodes (scaling them according to values in a JS array) when a certain node is selected. How would I go about doing this? The documentation for vis.js network objects is unenlightening beyond the source for this example.

Answer

Jos de Jong picture Jos de Jong · Sep 25, 2015

You can listen for click events to know when a user clicked a node.

network.on("click", function (params) {
  console.log(params);
});

If you have creates your nodes in a DataSet, you can simply update them and Network will be automatically updated accordingly:

nodes.update({id: 4, label: "changed label"});