Chartjs-Chartjs how to change decimal to integers X-axis

2👍

Try to put this in your options, it will begin at zero(so that bars with value 1 could be displayed) and Math.trunc will remove decimals.

scales: {
                xAxes: [{
                    ticks: {
                        beginAtZero: true,
                        userCallback: function (label, index, labels) {
                            if (Math.trunc(label) === label) {
                                return label;
                            }
                        }
                    }
                }]
            },

0👍

Check the options of chartjs scales. You can set up your min, max, and step of your scale. With that you could make it so only 0 and 1 are displayed.

Leave a comment