Change the Y-axis values from real numbers to integers in Chart.js

后端 未结 6 1177
忘了有多久
忘了有多久 2020-12-24 04:39

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. How can I change the number to integers?

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-24 05:15

    If you like to start in a different number than zero, you have to take that into account:

    var step  = 5;
    var max   = 90
    var start = 40;
    new Chart(income).Bar(barData, {
        scaleOverride: true,
        scaleSteps: Math.ceil((max-start)/step),
        scaleStepWidth: step,
        scaleStartValue: start
    });
    

提交回复
热议问题