chartjs / chartjs/Chart.js

Inconsistent step size behaviour when step size is not a divisor of (max - min)

Open
#12,165 0 comments 1 reaction 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### Expected behavior

I would expect to the chart to use the stepsize as long as possible and shrink the last interval: So if I have a chart with min:0, max:333 and stepSize: 50 it should:
- start from 0
- have ticks every 50 (0, 50, 100, 150, ...) with
- have a smaller interval up to the defined max (250, 300, 333)

### Current behavior

For smaller numbers, e.g. min:0, max:333 and stepSize: 50 the charts behaves as I would expect it.
See: [https://codepen.io/Pia-Gerhofer/pen/azNPgvm](https://codepen.io/Pia-Gerhofer/pen/azNPgvm)

But If I use bigger numbers with the same ratio: e.g. min: 0, max: 3333 and stepSize: 500 the charts distributes evently with 476,1 without considering my stepsize of 500 (476,1, 952,3, 1428,4, ...) : [https://codepen.io/Pia-Gerhofer/pen/LENMKOO](https://codepen.io/Pia-Gerhofer/pen/LENMKOO)

### Reproducible sample

https://codepen.io/Pia-Gerhofer/pen/LENMKOO

### Optional extra steps/info to reproduce

_No response_

### Possible solution

_No response_

### Context

We can't really use suggestedMin/suggestedMax because we want our users to decide which y-axis range they want to see currently and we want control over the stepsize at the same time.

### chart.js version

v4.5.1

### Browser name and version

Chrome Version 142.0.7444.176

### Link to your project

_No response_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.