Iam使用d3.js創建強制圖。 動態填充數組節點和鏈接。之後我'調用函數start()將節點追加到節點
function start() {
link = link.data(force.links(), function (d) {
return d.source.id + "-" + d.target.id;
});
link.enter().insert("line", ".node").attr("class", "link");
link.exit().remove();
node = node.data(force.nodes(), function (d) { return d.id; });
var nodeEnter = node.enter()
.append("circle")
.attr("r", 8);
nodeEnter.append("text")
.attr("dx", -40)
.attr("dy", 55)
.text(function (d) { return d.id });
node.exit().remove();
force.start();
}
節點都OK,鏈接都OK,但文字是不可見的! 如何在這種情況下正確追加文本節點?
爲什麼你使用 - 在DX ... ?? –
在[SVG - 文本元素](http://www.w3.org/TR/SVG/text.html#TextElement)中瞭解屬性,但在此之前,我猜你應該在強制佈局停止後向節點添加文本互動。 – pravin