Chart.js yAxes刻度stepSize不起作用(提琴) [英] Chart.js yAxes Ticks stepSize not working (fiddle)

查看:204
本文介绍了Chart.js yAxes刻度stepSize不起作用(提琴)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为yAxis创建了带有以下选项的折线图:

  yAxes:[{
ticks:{
精度:1,
stepSize:18.1,
最小值:148.5,
最大值:220.9
}
}]

因此,我希望yAxis的缩放比例如下:

  220.9 
202.8
184.7
166.6
148.5

但是,当我提供此信息时代码,我正在获取此数据。



请参阅此小提琴作为示例:




另一种方法是使用 suggestedMin suggestedMax 而不是 min max ,这允许Chart.js计算自己的最小 max


在您的情况下,您只需申请:

  y轴:[ {
刻度:{
maxTicksLimit:5,建议的
最小值:148.5,建议的
最大值:220.9,
步长:18.1,
},
}]


I have created a line chart with these options for the yAxis:

yAxes: [{
    ticks: {
        precision: 1,
        stepSize: 18.1,
        min: 148.5,
        max: 220.9
    }
}]

I would like, therefore, the yAxis scales to be like this:

220.9
202.8
184.7
166.6
148.5

However, when I provide this code, I am getting this data.

Please see this fiddle for an example: https://jsfiddle.net/wxLzdrcm/

How can I make the yAxis ticks add up like I have described?

解决方案

This question was asked at least twice (1, 2).

The solution is to use min and max values so that stepSize is a factor of max - min, allowing the chart to actually use the specified stepSize:

yAxes: [{
  ticks: {
    maxTicksLimit: 5,
    min: 144.8, // 18.1 * 8
    max: 235.3, // 18.1 * 13
    stepSize: 18.1,
  },
}]


An alternative would be using suggestedMin and suggestedMax rather than min and max, which allows Chart.js to calculate its own min and max:

In your case, you just need to apply:

yAxes: [{
  ticks: {
    maxTicksLimit: 5,
    suggestedMin: 148.5,
    suggestedMax: 220.9,
    stepSize: 18.1,
  },
}]

这篇关于Chart.js yAxes刻度stepSize不起作用(提琴)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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