我有一个沿X轴有时间刻度的条形图。
var xAxis = d3.svg.axis()
.scale(xScale)
.orient("bottom")
.tickFormat(RU.timeFormat("%b %Y"));
我需要将这些时间值传递给每个栏的工具提示。这是我的小提琴:https://jsfiddle.net/anton9ov/L9bkeypo/
答案 0 :(得分:1)
获取这样的刻度值:
.on("mouseover", function(d, i) {
//here i is the index of the bar
//selecting the text with the index
var tickValue = d3.select(d3.selectAll(".axis .tick text")[0][i]).text();
在工具提示中显示如下:
d3.select("#tooltip" )
.style("left" , xPosition + "px")
.style("top" , yPosition + "px")
.select("#label")
.text(tickValue);
工作代码here