Maybe this will help.
http://jsfiddle.net/S575k/4/
A few notes:
-
I reversed your y domain range from
.range([0, h-margin]);
to.range([h-margin, 0]);
This will fix the issue of the y-axis marks going in the wrong direction because the browser consider’s the origin(0,0)
point to the the upper-left corner, and not the bottom-left corner like in math. -
Because of this reversal I had to tweak your
.attr('height')
and.attr('y')
. -
A nice way to find the height of bar in a bar chart is to realize that the
yscale(0)
will give you the pixel-position of the bottom of the barchart. You can then doyscale(value) - yscale(0)
to get the pixel-height of your bars.