The bars in my bar chart using chartsjs are too wide. How can i make them thinner? Here is my code
<body>
<div class="chart-container" style="position: relative; height:40vh; width:80vw">
<canvas id="myChart" ></canvas>
</div>
<script src=" https://cdn.jsdelivr.net/npm/[email protected]/dist/chart.umd.min.js "></script>
<script>
const ctx = document.getElementById('myChart');
new Chart(ctx, {
type: 'bar',
data: {
labels: ['Males', 'Females'],
datasets: [{
label: 'Students Registrations by Gender',
data: [<?php echo $maleCount; ?>, <?php echo $femaleCount; ?>],
borderWidth: 1,
backgroundColor: ['rgb(54, 162, 235)', 'rgb(255, 99, 132)' ]
}]
}
});
</script>
</body>
I tried many options from chartsjs.org, but none of them fixed my problem.
For barchart in
chartjs, you may specify the barThickness value in the option block, such asSo change
to
will become the following (after specifying barThickness):