Skip to content

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

@peaches1307

Description

@peaches1307

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

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions