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 canvas/context becomes null until a few redraws later #79

Closed
ThenTech opened this issue Sep 6, 2023 · 4 comments
Closed

Chart canvas/context becomes null until a few redraws later #79

ThenTech opened this issue Sep 6, 2023 · 4 comments
Assignees
Labels
bug Something isn't working

Comments

@ThenTech
Copy link

ThenTech commented Sep 6, 2023

As mentioned here, I get the same error Cannot read properties of null (reading 'addEventListener') when using this plugin with react-chartjs-2. When rendering a tree type graph, at some point the chart.canvas reference becomes null thus throwing the error in createProxyAndListen from ChartJS.

If I add redraw={true} to the react-chartjs-2 Chart wrapper, and force it to recreate the graph every time, it does seem to work, but still throws the error 2 times.

I am not sure if I'm missing something else or where exactly the problem originates.

To Reproduce

Use react-chartjs-2's Chart and create a tree type chart.

Expected behavior

I expect the tree to be rendered the first time around.

Context

  • Version:
"chart.js": "4.4.0",
"react-chartjs-2": "5.2.0",
"chartjs-chart-graph": "4.2.3",
  • Browser: Chrome 116.0.5845.141
@ThenTech ThenTech added the bug Something isn't working label Sep 6, 2023
@sgratzl
Copy link
Owner

sgratzl commented Sep 9, 2023

can you reproduce the same problem with other chart.js chart types or just with this plugin?

@wualvinhardyangkasa
Copy link

I also experienced the same error Cannot read properties of null (reading 'addEventListener') with my own chart.js wrapper.

  • Version:
    "chart.js": "^4.4.0",
    "chartjs-chart-graph": "^4.2.5",

Here's the code that reproduce the problem:
https://codesandbox.io/p/sandbox/jolly-dew-vx64kl?file=%2Fapp%2Fpage.tsx%3A1%2C1

@sgratzl
Copy link
Owner

sgratzl commented Oct 9, 2023

should be fixed with the latest patch release.

The problem was that the async chart update after the layout process was done didn't check whether the chart was destroyed or not

@sgratzl sgratzl closed this as completed Oct 9, 2023
@sgratzl sgratzl self-assigned this Oct 9, 2023
@ThenTech
Copy link
Author

ThenTech commented Oct 9, 2023

That was it exactly. I can confirm that error is not thrown any more in the v4.2.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants