[英]D3js append nested elements
我有d3js强制布局。 我试图将嵌套元素添加到每个节点。 这是代码:
node
.append("div")
.attr("width", 60)
.attr("height", 60);
node.select("div")
.append("image")
.attr("xlink:href", function(d)
{
return d.url
})
.attr("x", -8)
.attr("y", -8)
.attr("width", 30)
.attr("height", 30);
node.select("div")
.append("text")
.attr("dx", 12)
.attr("dy", ".35em")
.text(function(d) { return d.name });
我得到的结果是:
<div width="60" height="60">
<image xlink:href="image.jpg" x="-8" y="-8" width="30" height="30">
</image>
<text dx="12" dy=".35em">mp3</text>
</div>
问题是我看不到图片和文字。
该怎么办?
谢谢
使用g元素,它进行了转换,可以将您的元素放置在正确的位置。 如果要使用div而不是g,则必须将div放置在svg顶部。
#canvas {
position: relative;
}
#canvas.div {
position: absolute;
top: 320px;
left: 150px;
}
画布是您附加svg的地方。 我在这里使用这种技术:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.