D3-JS的强制定向布局是否支持图像作为节点?
-
25-10-2019 - |
题
D3 有 强制导向图布局的演示.
我希望图形中的所有节点为图像,而不是圆圈。
所以我改变了
.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
不隶属于 StackOverflow