[Chartjs]-How to change the Y-axis values from float number to integer in chartjs?

16πŸ‘

βœ…

In your case, you can set stepSize property to 1 for y-axis ticks, to change the y-axis values from float number to integer.

options: {
   scales: {
      yAxes: [{
         ticks: {
            stepSize: 1
         }
      }]
   },
   ...
}

ᴅᴇᴍᴏ

var chart = new Chart(ctx, {
   type: 'line',
   data: {
      labels: ['Jan', 'Feb', 'Mar', 'Apr'],
      datasets: [{
         label: '# of votes',
         data: [1, 2, 3, 4]
      }]
   },
   options: {
      scales: {
         yAxes: [{
            ticks: {
               stepSize: 1
            }
         }]
      }
   }
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<canvas id="ctx"></canvas>

7πŸ‘

Try this:

window.onload = function() {
            var chartEl = document.getElementById("chart");
            window.myLine = new Chart(chartEl, {
                type: 'line',
                data: lineChartData,
                options: {
                    title:{
                        display:true,
                        text:'Kindmate - Chart Static Donate'
                    },
                    tooltips: {
                        enabled: true,
                        mode: 'index',
                        position: 'nearest',
                        custom: customTooltips
                    },
                      scales: {
                         yAxes: [{
                             ticks: {
                                 beginAtZero: true,
                                 callback: function(value) {if (value % 1   === 0) {return value;}}
                              }
                          }]
                     }
                }
            });

Leave a comment