Warm tip: This article is reproduced from serverfault.com, please click

chart.js-如何设置 Y 轴的最大值和最小值

(chart.js - How to set max and min value for Y axis)

发布于 2015-03-11 15:26:34

我正在使用来自http://www.chartjs.org/ 的折线图 在此处输入图片说明

正如你所看到的,Y 轴的最大值 (130) 和最小值 (60) 是自动选择的,我想要最大值 = 500 和最小值 = 0。这可能吗?

Questioner
Rajendra Thorat
Viewed
11
17.6k 2020-08-05 08:45:39

你必须覆盖规模,试试这个: (applies to ChartJS v1.x)

window.onload = function(){
    var ctx = document.getElementById("canvas").getContext("2d");
    window.myLine = new Chart(ctx).Line(lineChartData, {
        scaleOverride : true,
        scaleSteps : 10,
        scaleStepWidth : 50,
        scaleStartValue : 0 
    });
}