chartjs / chartjs/Chart.js

Time Cartesian Axis auto range does not respect datapoints beyond fixed Y-axis range

Open
#11,631 0 comments 0 reactions 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

When `min` and `max` are specified for Y-axis, data points with values out of this range should still be included in the Time Cartesian Axis range.

Following chart
```js
{
type: 'line',
data: { datasets: [{ data: [
{ x: '2024-01-06 07:00:00', y: 0 },
{ x: '2024-01-06 08:00:00', y: 2 },
{ x: '2024-01-06 09:00:00', y: 4 },
]}]},
options: { scales: {
x: { type: 'time' },
y: { min: 0, max: 3 },
}}
}
```

Should be displayed as follows
Screenshot 2024-01-06 at 12 37 17

Note that X-axis range is [7:00, 9:00].

### Current behavior

It is however displayed as follows

Screenshot 2024-01-06 at 12 36 51

Note that X-axis range is [7:00, 8:00].

It could be fixed either by
- Changing X-axis type to `category`
- Setting X-axis `suggestedMax` to `2021-11-06 09:00:00`
- Changing Y-axis range max

### Reproducible sample

https://stackblitz.com/edit/line-chart-5yxrkz?file=app%2Fapp.component.ts

### Optional extra steps/info to reproduce

_No response_

### Possible solution

_No response_

### Context

I was adding manual Y-axis range controls in HomeAssistant history graphs: https://github.com/home-assistant/frontend/pull/19297
Data values out of the specified range led to unexpected behaviour where some of data were not displayed at all.

### chart.js version

v4.4.1

### Browser name and version

_No response_

### 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.