d3: use anchor elements as chart labels
I am getting started with D3 and SVG but I haven't found anything clear on
how to add hyperlinks. Here is some code I have to write labels to the
left of the bars in a D3 bar chart. Is there a good sample somewhere to
convert these labels to hyperlinks (say objects in rangeData had an href
and name property)? I searched around a bit but haven't gotten much
further than the svg spec for adding an anchor element.
chart.selectAll(".bar.barLabel")
.data(rangeData)
.enter().append("text")
.attr("class", "bar")
.attr("x", 0)
.attr("y", function (d, i) { return height(i) + barHeight(y, i) /
2; })
.attr("dx", -20)
.attr("dy", ".35em")
.attr("text-anchor", "end")
.text(function (d) { return d.label; });
No comments:
Post a Comment