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

Is it possible to add the previous data without the chart going to the beginning? #1845

Open
paulodfavero opened this issue Feb 7, 2025 · 9 comments
Labels

Comments

@paulodfavero
Copy link

It's me again LOL
I need to keep the chart on the same place after load more past data.
This video shows the chart going to begin. I need to keep it in the same place.
https://github.com/user-attachments/assets/aca843e5-fde6-4774-ac33-fb4f44fd3b04

Thanks

@martynasma
Copy link
Collaborator

Would you be able to post your whole chart and data on CodePen/jsFiddle so that we can test?

@paulodfavero
Copy link
Author

paulodfavero commented Feb 10, 2025

CodePen/jsFiddle

https://codepen.io/Paulo-Favero/pen/RNwbeGK
I'm updating the chart with setTimeout only to simulate the behavior.

Image

As you can see, the chart goes to begin. My intention is to keep at the same place when timeout ends and load more data.

@martynasma
Copy link
Collaborator

Thanks. I'm still not sure what's the issue.

I load your chart, zoom in, the data updates, but the zoom stays at the place I zoomed to.

@paulodfavero
Copy link
Author

paulodfavero commented Feb 10, 2025

Thanks. I'm still not sure what's the issue.

I load your chart, zoom in, the data updates, but the zoom stays at the place I zoomed to.

The first load begin 11:46. After more data the chart goes to 11:00. I need to keep at 11:46 after more data loaded.

Image

@martynasma
Copy link
Collaborator

OK, so the axis tries to retain the same position, even if the underlying data scope changes.

If you need to keep exact same date scope across updates, you can follow this workflow:

  1. Before data update, log selectionMin and selectionMax of the X-axis.
  2. Updated data
  3. Once data is loaded, use axis' zoomToValues() to zoom it to same scope.
setTimeout(() => {
  var from = dateAxis.getPrivate("selectionMin");
  var to = dateAxis.getPrivate("selectionMax");
  const aggregatedTicksRef = [...oldDataAggregated, ...dataAggregated]
  valueSeries.data.setAll(aggregatedTicksRef);
  valueSeries.events.once("datavalidated", function(ev) {
    dateAxis.zoomToValues(from, to);
  })
},5000)

@paulodfavero
Copy link
Author

It works, but once data is loaded - after 5 seconds - the chart shakes.
Do I have to improve something in my code to avoid this shake behavior?
https://github.com/user-attachments/assets/dbbb1907-3032-4e05-a2ca-b639ea3ffe4c

@martynasma
Copy link
Collaborator

If you do not need the animation, you can disable it by passing 0 to zoom function:

dateAxis.zoomToValues(from, to, 0);

@paulodfavero
Copy link
Author

If you do not need the animation, you can disable it by passing 0 to zoom function:

dateAxis.zoomToValues(from, to, 0);

Keeps blinking. But now is more faster.
I'm sorry
https://github.com/user-attachments/assets/6ea680a7-1963-4c5f-bcf8-c14a1381b2e5

You can see on https://codepen.io/Paulo-Favero/pen/RNwbeGK

@paulodfavero
Copy link
Author

@martynasma
What if I push new more data on the valueSeries.data instead of setAll?
I think that setAll clear all data and after includes new data. Maybe this is blinking behavior.

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

No branches or pull requests

2 participants