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

Chart re-rendering seems to be broken #12

Closed
DDtKey opened this issue Jan 22, 2024 · 7 comments
Closed

Chart re-rendering seems to be broken #12

DDtKey opened this issue Jan 22, 2024 · 7 comments

Comments

@DDtKey
Copy link

DDtKey commented Jan 22, 2024

I'd like to update the chart on an event, approach with creating new chart seems broken:

Second call to render/render_mutate doesn't update the chart and moreover, I noticed that render call hangs. I.e it won't never finished.

Additionally, introducing update method could be considered (https://www.chartjs.org/docs/latest/developers/updates.html)

@DDtKey DDtKey changed the title Ability to re-render the chart seems to be broken Chart re-rendering seems to be broken Jan 22, 2024
@Billy-Sheppard
Copy link
Owner

Dayum, could you give me an example of your code? I've never had to use update as I repaint my chart as required but I can see how it would be useful.

Let me have a look into how feasible it is to add the update method :)

@DDtKey
Copy link
Author

DDtKey commented Jan 23, 2024

Sure, actually the code is open.
You can check this PR: DDtKey/exponential-buckets-explorer#1

You can start with trunk serve --open --features logging

You can pay attention to the console log, after any change it will be triggered but not finished

@DDtKey
Copy link
Author

DDtKey commented Jan 25, 2024

In fact, second render call fails with:

Uncaught Error: Canvas is already in use. Chart with ID '0' must be destroyed before the canvas with ID 'buckets-chart' can be reused.

@Billy-Sheppard
Copy link
Owner

I'm working on a solution at the moment, I'll let you know when its ready for testing.

@DDtKey
Copy link
Author

DDtKey commented Jan 25, 2024

Not sure if it may help, but I actually did such local patch:

# body of `render_chart` js function
- var chart = new Chart(ctx, obj);
+    var chart = Chart.getChart(ctx);
+    if (chart) {
+        chart.data.datasets = v.data.datasets;
+        chart.options = v.options;
+        chart.update();
+    } else {
+        new Chart(ctx, obj);
+    }

And it covered my needs pretty well - it dynamically re-renders the chart without destroying and jumps, but likely you have better idea how to support this.

To make it more clear - draft PR: #13

@Billy-Sheppard
Copy link
Owner

Try checking out my code in #14

If this solves your situation I'll merge it in.

@Billy-Sheppard
Copy link
Owner

I think this can be closed now.

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

No branches or pull requests

2 participants