Rachid Oussanaa Rachid Oussanaa - 6 months ago 28
HTML Question

how to change the Y-axis values from real numbers to integer in chartjs?

I have a chart that I want to include in my website using Chart.js. In the Y-axis it gives me real numbers instead of integers, and that's what I want, here's a picture of what i have now:

enter image description here

And that's the code:

var lineChartData = {

labels : ["2013/04/01","2013/03/31", "2013/03/30", "2013/03/29", "2013/03/28","2013/03/27", "2013/03/26"],

datasets : [
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : ["0", "2","1", "0", "1","0","1"]
}
]

}

var myLine = new Chart(document.getElementById("canvas").getContext("2d")).Bar(lineChartData);

Answer

Try this, where max is the highest value of your data.

var steps = 3;
new Chart(ctx).Bar(plotData, {
    scaleOverride: true,
    scaleSteps: steps,
    scaleStepWidth: Math.ceil(max / steps),
    scaleStartValue: 0
});