Sometimes, we want to set bar width with Chart.js 2 and JavaScript.
In this article, we’ll look at how to set bar width with Chart.js 2 and JavaScript.
How to set bar width with Chart.js 2 and JavaScript?
To set bar width with Chart.js 2 and JavaScript, we set the barThickness
and maxBarThickness
properties.
For instance, we write
const options = {
type: "bar",
data: [
//...
],
options: {
scales: {
xAxes: [
{
barThickness: 6,
maxBarThickness: 8,
},
],
},
},
};
to set the barThickness
to the bar thickness in pixels.
And we set the maxBarThickness
to the max bar thickness in pixels.
Conclusion
To set bar width with Chart.js 2 and JavaScript, we set the barThickness
and maxBarThickness
properties.