score:5

Accepted answer

This should help:

.on("mouseover", function(d)
 {
     d3.select(labels[0][d.index]).style("visibility","visible")
 })
.on("mouseout", function(d)
 {
     d3.select(labels[0][d.index]).style("visibility","hidden")
 })

score:3

Learning d3 myself here - also thanks very much to juvian

I find a more transparent way of coding this would be to say

.on("mouseover", function(d) { 
  d3.select(this).select("text").style("visibility", "visible") 
})

which selects the object you hover over (a group), selects the text inside it and changes the style to visible. This also avoids the need to make a labels variable which gets a bit messy with the array indexing.


Related Query