I'm using d3.stack()
to create a normalized stacked barchart.
But I'm having trouble accessing the relevant values of the inital dataset for a mousover tooltip.
serie.selectAll("rect")
.data(function(d) { return d; })
.enter().append("rect")
...
.on("mousemove", function(d){
let coords = d3.mouse(svg.node());
tooltip.style("left", coords[0] + "px");
tooltip.style("top", coords[1] - 70 + "px");
tooltip.style("display", "inline-block");
tooltip.html("HOW TO ACCESS DATA HERE?");
});
d
is the Array[2]
at this point with the values defining baseline / topline, d.data
is the complete original data object but is missing the information over which stack of the series I'm currently hovering.
Ideally I want the tooltip to show for a dataset like {name:"item1", foo:10, bar:20}
value: 10
percentage: 33%
when hovering above the foo
rect.
All the examples I've found are for D3v3 where you can simply use d.y
to access the relevant value but that doesn't seem to work any more with D3v4.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…