Anton Anton - 1 year ago 70
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:

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download