ChartJS:如何设置固定的Y轴最大值和最小值 [英] ChartJS: How to set fixed Y axis max and min

查看:845
本文介绍了ChartJS:如何设置固定的Y轴最大值和最小值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个折线图,我试图设置一个固定最大值和最小值.我尝试了关于SO的其他建议,但仍然无法正常工作.我的图表不断根据输入数据重新设置最大值和最小值.

I have a line chart which I'm trying to set a fixed max and min values. I have tried the other suggestions found on SO, but it still doesn't work. My chart keeps re-setting the max and min values depending on the incoming data.

以下是我当前传递给折线图的选项:

Here's my current options that I pass to my Line chart:

var options = {
        responsive: true,
        animation: false
};

我也尝试过这些设置:

var options = {
    scales: {
        animation: false,
        yAxes: [{
            display: true,
            ticks: {
                suggestedMin: -1,
                suggestedMax: 1
            }
        }]
    }
};

知道我在做什么错吗?

谢谢!

推荐答案

要固定yAxes标尺的最小值和最大值,请使用以下代码.

To fix min and max value for yAxes scale use the below code.

options:{
            scales: {
                yAxes : [{
                    ticks : {
                        max : 1,    
                        min : -1
                    }
                }]
            }
        }

suggestedMax 仅在传入数据低于建议的Max值时才有效. suggestedMin 仅在传入数据大于建议的Min值时有效.

suggestedMax will only works when incoming data is lower than suggestedMax value. suggestedMin will works only when incoming data is greater than suggestedMin value.

这篇关于ChartJS:如何设置固定的Y轴最大值和最小值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆