D3定向图

Nik*_*jan 5 directed-graph d3.js

我使用以下示例生成有向图

http://bl.ocks.org/1153292

我想添加一个click事件,以便当用户单击某个节点时,将显示该节点的标题

到目前为止我做到了这一点

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

};
Run Code Online (Sandbox Code Playgroud)

请告诉我如何显示

Chr*_*che 4

您可以使用.on()为了有一个点击事件

circle.on("click", function(d) {
    alert(d.name)
})
Run Code Online (Sandbox Code Playgroud)

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