D3js - change Vertical bar chart to Horizontal bar chart

前端 未结 4 1852
花落未央
花落未央 2020-11-27 07:47

I have a vertical bar chart that is grouped in pairs. I was trying to play around with how to flip it horizontally. In my case, the keywords would appear on the y axis, and

4条回答
  •  情书的邮戳
    2020-11-27 08:27

    Here is the procedure I use in this case:

    1) Inverse all Xs and Ys

    2) Remember that the 0 for y is on top, thus you will have to inverse lots of values as previous values for y will be inversed (you don't want your x axis to go from left to right) and the new y axis will be inversed too.

    3) Make sure the bars display correctly

    4) Adapt legends if there are problems

    This question may help in the sense that it shows how to go from horizontal bar charts to vertical: d3.js histogram with positive and negative values

提交回复
热议问题