[Chartjs]-How to properly scale large numbers in ChartJS/react-chartjs-2

1👍

You can use a logarithmic scale:

const options = {
  type: 'bar',
  data: {
    labels: ["January", "February", "March", "April"],
    datasets: [{
      label: '# of Votes',
      data: [440000000000, 3000000000, 1000000000, 880147000],
      backgroundColor: 'pink'
    }]
  },
  options: {
    indexAxis: 'y',
    scales: {
      x: {
        type: 'logarithmic'
      }
    }
  }
}

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>
  </script>
</body>

Leave a comment