Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 Regression: Line doesn't draw when points are out of range #9564

Open
beibean opened this issue Aug 18, 2021 · 4 comments
Open

v3 Regression: Line doesn't draw when points are out of range #9564

beibean opened this issue Aug 18, 2021 · 4 comments

Comments

@beibean
Copy link

beibean commented Aug 18, 2021

Expected Behavior

Line should be drawn as it was in v2.9.4.

Current Behavior

When we have a line with two points out of X range (min/max), this line is not drawn.

Steps to Reproduce

For a linear graph:

  • Set x.min: 0
  • Set x.max: 100
  • Set two points laying at x: -10 and x: 100

See this project

Context

We need this in our application, where you can see temperature changes in different zooms levels such as day or hour. With this behaviour, when you move to an hour zoom where temperature has not changed, you see an empty graph which is very ugly.

Environment

  • Chart.js version: 3.5.0
  • Link to your project: See this project
@kurkle
Copy link
Member

kurkle commented Aug 20, 2021

This is actually the y-scale determining its range so that the line is drawn outside. (change suggestedMax to 50 in that reproduce and the line is visible)

Some thoughts:
I think a proper way of handling this would be for the line to interpolate its values at the edges of x-range, but currently the interpolation needs points to be updated - so it would need another pass on the update cycle.
Maybe the interpolation could be done from the parsed array instead to avoid the 2nd pass.

@beibean
Copy link
Author

beibean commented Aug 23, 2021

This is actually the y-scale determining its range so that the line is drawn outside. (change suggestedMax to 50 in that reproduce and the line is visible)

I know changing the suggestedMax would work for the example case. But anyway, it does not work as expected. If you don't provide any suggested limits, y-scale is not properly calculated and line would not be drawn neither.

Is there any plan to fix this issue within comming versions?

@beibean
Copy link
Author

beibean commented Dec 13, 2021

@kurkle

I just came back to use chart.js again. I upgraded to last version (v3.6.2) and bug still occurrs.

Any plans to fix it in the near future?

Edit: Here is project repo with new chart.js

@beibean
Copy link
Author

beibean commented Dec 15, 2021

If anyone is interested in the partial solution I have applied on app side:

  • Detect when we have only two points and they are out of range on X-axis.
  • In that case, configure sugestedMin and sugestedMax for Y-axis. As min/max of those two points.
  • Chartjs now renders properly.
  • Remember to reset sugestedMin and sugestedMax when plotting new data.

Anyway, I think this should be integrated within chartjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants