Take a look: http://bl.ocks.org/2973775
Note that in jsFiddle you are not actually using d3. But you can easily add it to get a tooltip to see here :
var svg = d3.select("svg").attr("width", 400).attr("height", 400); var vis = svg.append('g'); var txt = vis.append('text') .attr({ transform: 'translate(5,20)', fill:'red'}) .text("Node Info"); d3.selectAll('.bar') .on("mouseover", function(d) { var mousePos = d3.mouse(this); txt.text(mousePos); txt.attr({transform: 'translate(' + mousePos + ')'}); }) .on("mousemove", function(d) { var mousePos = d3.mouse(this); txt.attr({transform: 'translate(' + mousePos + ')'}); });
To find out which bar you will have to look at the mouse position x. You should consider using d3 scale for this (it will appear in both directions - check the invert function).
source share