[英]How to add label to edges in d3 graph
請參閱http://bl.ocks.org/rkirsling/5001347
它顯示了一些節點和它們之間的邊緣。 你能告訴你要添加哪些代碼以及邊緣有標簽的地方。 您可以為標簽假設任何合適的位置,您也可以假設任何標簽文本。 謝謝。
您可以像添加鏈接本身的路徑一樣添加標簽。 您需要做的就是根據鏈路連接的兩個節點的位置計算位置。 代碼看起來像這樣。
svg.selectAll("text").data(links).enter()
.append("text")
.attr("x", function(d) { return d.source.x + (d.target.x - d.source.x)/2; })
.attr("y", function(d) { return d.source.y + (d.target.y - d.source.y)/2; })
.text(function(d) { return d.something; });
請注意,在tick
函數中,您還需要更新標簽的位置。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.