Chartjs-Change axis scale to be round numbers instead of decimal โ€“ chart.js

2๐Ÿ‘

โœ…

You are using v2 syntax while using v3, in v3 all scales are objects and no arrays anymore. For all changes please read the migration guide

Exaple:

const options = {
  type: 'bar',
  data: {
    labels: ["Red", "Blue", "Yellow"],
    datasets: [{
      label: '# of Votes',
      data: [1, 2.5, 1.5],
      backgroundColor: ["Red", "Blue", "Yellow"]
    }]
  },
  options: {
    scales: {
      y: {
        ticks: {
          stepSize: 1
        },
      }
    }
  }
}

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.7.0/chart.js"></script>
</body>

Leave a comment