williaster / data-ui

A collection of data-rich UI components 📈

Home Page:https://williaster.github.io/data-ui/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to create a bar chart with bars of fixed width, regardless of the number of bars?

okanji opened this issue · comments

Am trying to find a way have fixed bar widths for a bar chart. Currently this is my xScale, can I pass anything else to it that would fix the bar width?

xScale={{ type: 'band', paddingInner: 0.15 }}

Hey @okanji thanks for checking out @data-ui. This currently is not possible, the bar width is auto-computed based on

  • the # of bars
  • the width passed to the chart
  • the margin passed to the chart

So you can back compute the size you want, and pass in the appropriate width/margin for the number of data points you have, but otherwise you cannot specify this. Most of the time users want bars to fit in the chart/be auto-computed.

Thanks for your quick and detailed response!