I am trying to show text on mouseover
on links, but I am not able to see any text. I only can change the colour like in the code attached below.
Any help with the tool tips is also welcome as I tried that too.
I am trying to show text on mouseover
on links, but I am not able to see any text. I only can change the colour like in the code attached below.
Any help with the tool tips is also welcome as I tried that too.
Try this way.
link.on('mouseover', function(d, i) {
d3.select(this).style("stroke", "red");
if (!d3.select("#link-label-" + i).node()) {
svg.append("text")
.attr("id", "link-label-" + i)
.attr("font-family", "Arial, Helvetica, sans-serif")
.attr("x", function() {
if (d.target.x > d.source.x) {
return (d.source.x + (d.target.x - d.source.x) / 2);
} else {
return (d.target.x + (d.source.x - d.target.x) / 2);
}
})
.attr("y", function() {
if (d.target.y > d.source.y) {
return (d.source.y + (d.target.y - d.source.y) / 2);
} else {
return (d.target.y + (d.source.y - d.target.y) / 2);
}
})
.attr("fill", "Black")
.style("font", "normal 12px Arial")
.attr("dy", ".35em")
.text(function() {
return d.source.name + " - " + d.target.name;
});
}
}).on('mouseout', function(d, i) {
d3.select(this).style("stroke", d.target.group == 2?"black":"#9ecae1");
d3.select("#link-label-" + i).remove();
});
Updated fiddle
Since your circle
s are already bound to data you can do something like this
d3.select('circle')
.attr('title', function(d){
return d.name; //or whatever
});
an use the default browser tooltip