Listen for data update #11137
-
I have a chart that gets data dynamically over time based on user interaction. I'm using chartjs-plugin-zoom to pan through the data in the horizontal direction because the data eventually goes of the screen. Whenever I update the chart, it scrolls all the way to the left. It eventually can get tedious to see new data, because you constantly have to manually pan all the way to the right. I've been trying to create a simple plugin that will automatically scroll to the right when the chart's data has been updated but I can't find an event or callback in the plugin interface that will allow me to do that. I was trying the afterDatasetsUpdate function in my plugin, but that updates much more often than my data so I'm assuming that means something else. Can anyone point me in the right direction for listening for chart updates? P.S. If it helps I'm using sveltekit and svelte-chartjs to interact to chartjs |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
How exactly are you updating the chart? Sounds like you could be replacing the data or re-creating the entire chart? |
Beta Was this translation helpful? Give feedback.
-
I solved it by just having the svelte component export a const function that manually pans the graph. The parent classes just call the function on data update. (I did have to use set timeout however because the graph automatically scrolls to the left, but a delay of 10ms was more than enough and unnoticeable) |
Beta Was this translation helpful? Give feedback.
I solved it by just having the svelte component export a const function that manually pans the graph. The parent classes just call the function on data update. (I did have to use set timeout however because the graph automatically scrolls to the left, but a delay of 10ms was more than enough and unnoticeable)