[Chartjs]-Consider 60 as zero in bar chart

1👍

You can use floating bars for this by instead of providing an array with values you provide an array with arrays, in which each array is a bar with a start and end value, in here you always provide 60 and the value you want:

const options = {
  type: 'bar',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
      label: '# of Votes',
      data: [
        [12, 60],
        [50, 60],
        [3, 60],
        [75, 60],
        [20, 60],
        [63, 60]
      ],
      backgroundColor: 'pink'
    }]
  },
  options: {}
}

const ctx = document.getElementById('chartJSContainer').getContext('2d');
new Chart(ctx, options);
<body>
  <canvas id="chartJSContainer" width="600" height="400"></canvas>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.9.1/chart.js"></script>
</body>

Leave a comment