gpt4 book ai didi

javascript - d3-js 的 Force-Directed Layout 是否支持图像作为节点?

转载 作者:可可西里 更新时间:2023-11-01 02:19:38 25 4
gpt4 key购买 nike

d3a demo of a Force-Directed Graph Layout .

我希望图中的所有节点都是图像,而不是圆圈。

所以,我变了

 .append("svg:circle")
.attr("class", "node")
.attr("cx", function(d) { return d.x; })
.attr("cy", function(d) { return d.y; })
.attr("r", 5)
.style("fill", function(d) { return fill(d.group); })
.call(force.drag);

.append("xhtml:img")
.attr("src", "http://a577.phobos.apple.com/us/r1000/081/Purple/12/61/13/mzi.lgqdzwfu.png")
.call(force.drag);

但是我看不到任何图像。我做错了什么?

最佳答案

node.append("svg:image")
.attr("class", "circle")
.attr("xlink:href", "https://d3nwyuy0nl342s.cloudfront.net/images/icons/public.png")
.attr("x", "-8px")
.attr("y", "-8px")
.attr("width", "16px")
.attr("height", "16px");

这里是一个使用图像作为节点的例子:http://bl.ocks.org/950642

关于javascript - d3-js 的 Force-Directed Layout 是否支持图像作为节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7306250/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com