[Bar Chart] Set max width of a bar #1035
-
The following was originally posted as an issue by @wisyr in #1032, moving it to a discussion. tl;dr - Is there a way to set a max width of a bar in charts but still keep it dynamic? The issue is related with bar width. If there's enough of data, a single bar looks just okey. But if there's no enough data, the bars are getting too wide. Is there a way to somehow set a max width of a single bar? But still keep it dynamic so it is responsive when chart is resizing. Playground: https://codesandbox.io/s/holy-pine-i5sp2?file=/Example.tsx Thank you for such an outstanding library! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
@wisyr So to get this behavior, you need to compute the necessary padding (using the available chart Note you can get different behavior by setting Hope that helps, let me know if I can clarify anything further. |
Beta Was this translation helpful? Give feedback.
-
Dear @williaster |
Beta Was this translation helpful? Give feedback.
@wisyr
barWidth
for aband
type scale is determined by the available chartwidth
(set as the scale'srange
) and thepadding
(paddingInner
+paddingOuter
) set on thescale
. This is described in detail and depicted ind3-scale
's docs:So to get this behavior, you need to compute the necessary padding (using the available chart
width
and number of bars) in order to achieve your desired maximum width. Here's a sandbox that demonstrates the gist of it.Note you can get different behavior by setting
scale.padding
(above, in sandbox) vsscale.paddingInner
(below):Hope that helps, let me know if I can clarify anything further.