Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

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

Open AnMakc opened this issue 2 years ago • 0 comments

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

  • 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

AnMakc avatar Jan 06 '24 15:01 AnMakc