[英]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.