D3 Directed graphs

谁说我不能喝 提交于 2019-12-04 12:25:00

问题


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


回答1:


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/



来源:https://stackoverflow.com/questions/10913407/d3-directed-graphs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!