Skip to content

Maximum bar thickness #3036

@punit-shah

Description

@punit-shah

I noticed that v2.2.0-rc.2 introduced a barThickness option to set the thickness of a bar to a fixed width.

I sometimes deal with charts with perhaps two or three bars. Chart.js's calculated bar widths would fill the whole chart area, resulting in very wide bars. I thought barThickness would be the perfect solution for this!

However, in practice I found it is not ideal. Setting the bar thickness to a fixed value means the bar will always stay at that width, which isn't what we want if we want our charts to be responsive.

A barThickness that looks great on a big screen would cause the bars to overlap on small screens.

http://codepen.io/anon/pen/AXdvEr This chart for example looks great with a barThickness of 100 at a viewport width of 1008px, but resize the screen to 600px wide and the bars are overlapping.

My solution is a maxBarThickness option instead. Chart.js would use its normal calculated bar thickness, unless it is greater than the maxBarThickness value, in which case it would use the maxBarThickness.

return calculatedBarThickness > maxBarThickness ? maxBarThickness : calculatedBarThickness;

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions