如何设置 Y 轴的最大值和最小值最大值、如何设置、最小值

2023-09-07 11:21:41 作者:黑是因为我不想白活一辈子

我正在使用 http://www.chartjs.org/ 的折线图

I am using line chart from http://www.chartjs.org/

正如您所见,Y 轴的最大值 (130) 和最小值 (60) 是自动选择的,我希望最大值 = 500 和最小值 = 0.这可能吗?

As you can see max value (130) and min value (60) for Y axis are chosen automatically , I want max value = 500 and min value=0. Is this possible?

推荐答案

你必须覆盖比例,试试这个:(适用于 ChartJS v1.x)

You have to overrride the scale, try this: (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 
    });
}