Friday, May 10, 2024
 Popular · Latest · Hot · Upcoming
123
rated 0 times [  127] [ 4]  / answers: 1 / hits: 16146  / 8 Years ago, thu, march 10, 2016, 12:00:00

I have a network graph of nodes and edges and would like to get the node data once it gets clicked. e.g,


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

But this just returns some internal id [105]. Is there a way to get the actual data that is associated with the node?


More From » vis.js

 Answers
28

The node ids that you get in the properties is not some internal id, but these are the id's of the nodes that you defined yourself. You can simply read the node's data from your own DataSet with nodes like:



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);
});

[#62993] Monday, March 7, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
adriannemyiag

Total Points: 504
Total Questions: 105
Total Answers: 99

Location: Ecuador
Member since Thu, Apr 22, 2021
3 Years ago
;