Access node data in vis.js handler

I have a network graph of nodes and edges and would like to receive node data after clicking it. I currently have

var network = new vis.Network(container, data, options);
network.on( 'click', function(properties) {
    console.log('clicked node ' + properties.nodes);
});

But that just gives me an internal identifier [105]. Is there a way to get the actual data related to node.

+4
source share
1 answer

The node identifiers that you get in the properties are not "some internal identifier", but they are the identifiers of the nodes that you yourself have defined. You can simply read the node data from your own DataSetwith nodes such as:

var nodes = new vis.DataSet([...]);
var edges = new vis.DataSet([...]);
var data = {nodes: nodes, edges: edges};

var network = new vis.Network(container, data, options);
network.on( 'click', function(properties) {
    var ids = properties.nodes;
    var clickedNodes = nodes.get(ids);
    console.log('clicked nodes:', clickedNodes);
});
+8
source

All Articles