[Chartjs]-The bar that contains a low value is almost invisible on the chartjs

2👍

This is how the chart works and how the data is correctly represented. But if you want all bars to be more visible you can use the minBarLength option. This ensures the bars are at least that many pixels high.

This can be configured on a dataset level so only bars from that dataset are that high or on a chart level in the options of the yAxes although the chart level options are deprecated and dont work in V3 anymore:

const options = {
  type: 'bar',
  data: {
    labels: ["Red", "Blue", "Yellow", "Green", "Purple", "Orange"],
    datasets: [{
        label: '# of Votes',
        data: [1200, 19, 3, 5, 2, 3],
        backgroundColor: 'pink'
      },
      {
        label: '# of Points',
        data: [7, 11, 5, 8, 3, 7],
        backgroundColor: 'orange',
        minBarLength: 100, // Set the min bar length on a dataset level so only the orange bars will be at least 100 pixels high
      }
    ]
  },
  options: {
    scales: {
      yAxes: [{
        minBarLength: 100, // Set the min bar length on a chart level so all bars will be at least 100 pixels high
      }]
    }
  }
}

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/2.9.4/Chart.js"></script>
</body>

Leave a comment