问题
Here is my d3.js code
var circles = vis.selectAll("circle").data(data)
circles
.enter()
.append("svg:circle")
.attr("stroke", "black")
.attr("cx", function (d) { return xRange(d.year); })
.attr("cy", function (d) { return yRange(d.count); })
.style("fill", function(d,i){return color(i);})
.append("svg:title")
.text(function (d) { return d.corpus; })
In the end i have appended a tooltip to the circles.I tried to attach jquery tipsy tooltip to the circles but did'nt work.Here is how i did it(i followed http://bl.ocks.org/1373263
)
var circles = vis.selectAll("circle").data(data)
circles
.enter()
.append("svg:circle")
.attr("stroke", "black")
.attr("cx", function (d) { return xRange(d.year); })
.attr("cy", function (d) { return yRange(d.count); })
.style("fill", function(d,i){return color(i);})
$('svg circle').tipsy({
gravity: 'w',
html: true,
title: function (d) {
return d.corpus;
}
});
But its not working.
回答1:
You are missing this.data
$('svg circle').tipsy({
gravity: 'w',
html: true,
title: function (d) {
var d = this.__data__;
return d.corpus;
}
});
来源:https://stackoverflow.com/questions/13568802/jquery-tipsy-tooltip-not-working-with-d3-js-circles