我是 d3/HTML/JS 的 super 初学者,我有一个关于向图中的节点添加链接的问题。我的所有代码都基于:https://gist.github.com/mbostock/7607999
我想添加一个链接,指向每个节点的另一个 html 文件。考虑到代码的结构,这可能吗?
最佳答案
这是实现此目的的简单方法:
node = node
.data(nodes.filter(function(n) { return !n.children; }))
.enter()
.append('a')
.attr("xlink:href", 'http://www.google.com' /*function(d){return d.url;}*/)
.append("text")
.attr("class", "node")
...
我注释掉了基于数据建立链接的代码(即您的输入数据中会有一个 url 字段)。
每个请求,数据中的 url 示例:
"children": [
{
"name": "John Doe",
"size": 1458,
"url": "http://www.johndoe.com"
...
关于javascript - d3 : Adding links to nodes in hierarchical edge bundling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22726280/