Your mistake here:
link.enter().insert("path", "g")
.attr("class", "link")
...
...
link.append("text")
.attr("font-family", "Arial, Helvetica, sans-serif")
.attr("fill", "Black")
This code will put the text in the DOM path, which is incorrect. DOM text should never be inside the DOM path.
The correct code should be like this:
var link = svg.selectAll("path.link")
.data(links);
link.enter().insert("text")
.attr("font-family", "Arial, Helvetica, sans-serif")
.attr("fill", "Black")
.style("font", "normal 12px Arial")
.attr("transform", function (d) {
return "translate(" + (d.target.y - 30) + "," + (d.target.x - 10) + ")";
})
.attr("text-anchor", "middle")
.text(function (d) {
console.log(d.target.label);
return d.target.label;
});
Full working code here .
Cyril source
share