chartjs / Chart.js

Simple HTML5 Charts using the <canvas> tag
https://www.chartjs.org/
MIT License
64.5k stars 11.89k forks source link

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

Open AnMakc opened 9 months ago

AnMakc commented 9 months ago

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

{
  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

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