Anton Anton - 10 months ago 43
Javascript Question

How to pass the tick value on to the tooltip

I have a bar chart with a time scale along X axis.

var xAxis = d3.svg.axis()
.tickFormat(RU.timeFormat("%b %Y"));

I need to pass these time values on to the tooltips for every bar. Here's my fiddle:


Get the tick value like this:

.on("mouseover", function(d, i) {
    //here i is the index of the bar
    //selecting the text with the index    
    var tickValue =".axis .tick text")[0][i]).text();

Display in the tooltip like this:"#tooltip" )
    .style("left" , xPosition + "px")
  .style("top" , yPosition + "px")

working code here