D3 Directional Graphics

I used the following example to create directed graphs

http://bl.ocks.org/1153292

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

So far i have done it

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 tell me how to display this.

+5
source share
1 answer

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

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

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

+4
source

All Articles