Skip to content

[Bar Chart] Set max width of a bar #1035

Answered by williaster
williaster asked this question in Q&A
Discussion options

You must be logged in to vote

@wisyr barWidth for a band type scale is determined by the available chart width (set as the scale's range) and the padding (paddingInner + paddingOuter) set on the scale. This is described in detail and depicted in d3-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) vs scale.paddingInner (below):

Hope that helps, let me know if I can clarify anything further.

Replies: 2 comments 2 replies

Comment options

You must be logged in to vote
2 replies
@valtism
Comment options

@rajatdangat07
Comment options

Answer selected by williaster
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants