D3导向图 [英] D3 Directed graphs

查看:140
本文介绍了D3导向图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

到目前为止我做了这个

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

};

请告诉我如何显示

推荐答案

您可以使用 .on()以获得点击事件

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/

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

这篇关于D3导向图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆