D3 Graph Drawing with labels, first few labels won't appear
JSFiddle: http://jsfiddle.net/3b8Ax/4/
I've created random data, and graphed it using d3 while trying to learn
it. When putting labels on the bars however, the first 6 never get a
label, and I'm going crazy trying to find out why. Does anyone have any
input? I'm still learning, so the code is probably very un-optimized and
messy. Thanks!
Text drawing function:
svg.selectAll("text").data(dataset).enter().append("text")
.text(function (d) { return d; })
.attr("x", function (d, i) { console.log(dataset);return i
* ((w - SidebarPadding) / dataset.length) + SidebarPadding
+ (w / dataset.length - padding) / 2; })
.attr("y", function (d) {
if (scale(d) > (h - 10)) { return h - 2; }
return scale(d) + 10;
})
.attr("font-family", "sans-serif")
.attr("font-size", "11px")
.attr("fill", "orange")
.attr("text-anchor", "middle")
.attr("font-size", "50%");
No comments:
Post a Comment