sgratzl / chartjs-chart-graph

Chart.js Graph-like Charts (tree, force directed)
https://www.sgratzl.com/chartjs-chart-graph/
MIT License
180 stars 23 forks source link

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

Closed ThenTech closed 1 year ago

ThenTech commented 1 year ago

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

sgratzl commented 1 year ago

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

wualvinhardyangkasa commented 1 year ago

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

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

sgratzl commented 1 year ago

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

ThenTech commented 1 year ago

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