[Chartjs]-How to set the chartjs bar graph scale to the highest value in the result data

3👍

There is an easier workaround to do this. Just add a null to the end of your data array, like so

var barData = {
    labels: ["January", "February", "March", "April", "May", "June"],
    datasets: [
        {
            fillColor: "#48A497",
            strokeColor: "#48A4D1",
            data: [45, 47, 124, 56, 70, 60, null]
        }
    ]
};

0👍

I have taken the greatest value from the data and divide it with the ScaleSteps and set in scaleStepWidth so it becomes custom scale according to my highest value.

 var myBarChart = new Chart(document.getElementById("id").getContext("2d")).Bar(BarChart, {
    animation: false,
    scaleOverride: true,
    scaleSteps: 10,
    scaleStartValue: 0,
    scaleStepWidth: 20
});

Now the Sacle will be 0 to 200. which is OK for me.

Leave a comment