d3 bar chart is upside down

前端 未结 3 1216
甜味超标
甜味超标 2021-01-02 03:11

I have a simple bar chart drawn in d3, with vertical bars: http://jsfiddle.net/philgyford/LjxaV/2/

However, it\'s drawing the bars down, with the baseline at the top

3条回答
  •  遥遥无期
    2021-01-02 03:35

    Per the d3 basic bar chart : http://bl.ocks.org/mbostock/3885304

    You are correct in inverting the range.

    Additionally, your rectangles should be added like this:

        .attr('y', function(d) { return y(d.percent); } )
        .attr('height', function(d,i){ return height - y(d.percent); });
    

提交回复
热议问题