Chart.js yAxes Ticks stepSize 不起作用(小提琴)

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

问题描述

我已经为 yAxis 创建了一个带有这些选项的折线图:

yAxes: [{滴答声:{精度:1,步长:18.1,分钟:148.5,最大值:220.9}}]

因此,我希望 yAxis 可以这样缩放:

220.9202.8184.7166.6148.5

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

请看这个小提琴的例子:


另一种方法是使用 suggestedMinsuggestedMax 而不是 minmax,这允许 Chart.js计算自己的minmax:

在你的情况下,你只需要申请:

yAxes: [{滴答声:{maxTicksLimit: 5,建议Min: 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 Ticks stepSize 不起作用(小提琴)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Update another component when Formik form changes(当Formik表单更改时更新另一个组件)
Formik validation isSubmitting / isValidating not getting set to true(Formik验证正在提交/isValiating未设置为True)
React Validation Max Range Using Formik(使用Formik的Reaction验证最大范围)
Validation using Yup to check string or number length(使用YUP检查字符串或数字长度的验证)
Updating initialValues prop on Formik Form does not update input value(更新Formik表单上的初始值属性不会更新输入值)
password validation with yup and formik(使用YUP和Formick进行密码验证)