How to fix these spacing between bars ? when i have few data its become long width spacing.
What i want is
- fixed bar size
- fixed spacing between bars
- fit-content of canvas width so when there just a few data, its become compact and if its have much data , its become long
Note: My chart.js version is 4.4.0
2
Answers
To adjust the spacing between bars in a chart created with Chart.js, you generally have to tweak a few configuration options related to the chart’s scales and dataset. The spacing can be influenced by the barThickness, categoryPercentage, and barPercentage properties.
Look at the demo of this sample chart as it will be similar in your code I am guessing.
var ctx = document.getElementById(‘myChart’).getContext(‘2d’);
And now your requirements will fit in as per three things below:
hide the grid lines.
size based on the container width.
Hope this helps. Let me know how it goes.