I'm making a bar chart with the following code:
svg.selectAll(".bar")
.data(data)
.enter().append("rect")
.attr("class", "bar")
.attr("x", function(d) {
return x(d.value) - barWidth / 2;
})
.attr("width", barWidth)
.attr("y", function(d) {
return y(d.frequency);
})
//.attr("height", 0)
//.transition()
.attr("height", function(d) {
return height - y(d.frequency);
});
If I add the commented-out lines, then the bar transitions from height 0 to its proper height; however, for some reason instead of "growing" up from the x-axis, the bars start out at their highest values, and "grow" down towards the x-axis. Why is this happening? How can I fix this?