D3js - change Vertical bar chart to Horizontal bar chart

前端 未结 4 1841
花落未央
花落未央 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:22

    An alternative is to rotate the chart (see this). This is a bit hacky as then you need to maintain the swapped axes in your head (the height is actually the width etc), but it is arguably simpler if you already have a working vertical chart.

    An example of rotating the chart is below. You might need to rotate the text as well to make it nice.

    _chart.select('g').attr("transform","rotate(90 200 200)");
    

提交回复
热议问题