Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

D3 Directed graphs

I have used the following example to generate directed graphs

http://bl.ocks.org/1153292

I want to add a click event so that when the user clicks on a node, the heading of the node is displayed

So far i did this

var circle = svg.append("svg:g").selectAll("circle")
    .data(force.nodes())
  .enter().append("svg:circle")
    .attr("r", 6)
    **.on("mouseup", disp)**
    .call(force.drag);
     ;

function disp() {
    alert("Display the heading of the node clicked here");

};

Please advise me how to display that

like image 919
Nikhil Mahajan Avatar asked Oct 08 '22 15:10

Nikhil Mahajan


1 Answers

You can use the .on() in order to have a click event

circle.on("click", function(d) {
    alert(d.name)
})

jsFiddle: http://jsfiddle.net/chrisJamesC/HgHqy/

like image 100
Christopher Chiche Avatar answered Oct 12 '22 10:10

Christopher Chiche