react-chartjs-2 icon indicating copy to clipboard operation
react-chartjs-2 copied to clipboard

Problem with redraw and destroy

Open mmtmr opened this issue 5 years ago • 17 comments

i have the same problem, I have added redraw property to true , Without redraw property my chart works fine, but when i dynamically add data to chart, it draws chart in wierd ways, basically few labels from x-axis is still left over , even when they are not there in new data. I was hoping redraw would fix it, but it gives error. I think it may be a bug in redraw , it is not destroying the chart before redrawing

Originally posted by @kabeer10395 in https://github.com/reactchartjs/react-chartjs-2/issues/675#issuecomment-879675154

I also have the same problem, it bugs me that the chart is only updated after the second attempt of generating it. It means that when I am generating Chart 8, it shows Chart 7 and so on.

Issue is replicated here: https://codesandbox.io/s/crazy-curran-obsg2?file=/src/App.jsx

mmtmr avatar Oct 14 '21 17:10 mmtmr

I am getting the same issue with the redraw. Any update on this ?

varun761 avatar Oct 19 '21 07:10 varun761

@mmtmr Did you get any solution regarding this ?

varun761 avatar Oct 19 '21 07:10 varun761

Issue is replicated here: https://codesandbox.io/s/crazy-curran-obsg2?file=/src/App.jsx

@mmtmr Hi. In your example there are no rendered charts, can you fix it?

dangreen avatar Oct 19 '21 12:10 dangreen

Issue is replicated here: https://codesandbox.io/s/crazy-curran-obsg2?file=/src/App.jsx

@mmtmr Hi. In your example there are no rendered charts, can you fix it?

Sorry, I have fixed it already.

mmtmr avatar Oct 19 '21 12:10 mmtmr

Pls

atakanyurttutann avatar Oct 19 '21 14:10 atakanyurttutann

Hi, i've tried but can't fix my problem that is like your problem. Have another solution to use redraw?

FernandoVeras avatar Oct 19 '21 20:10 FernandoVeras

@mmtmr Did you get any solution regarding this ?

Hi, i've tried but can't fix my problem that is like your problem. Have another solution to use redraw?

Sorry I did not, that's why I am also waiting for a fix here. Maybe you can try implementing states as stated here.

mmtmr avatar Oct 20 '21 14:10 mmtmr

https://codesandbox.io/s/crazy-curran-obsg2?file=/src/App.jsx

@mmtmr Your example is still empty. Please make issue reproduction - it will help us to find the problem and fix it.

Снимок экрана 2021-10-20 в 21 40 48

dangreen avatar Oct 20 '21 14:10 dangreen

https://codesandbox.io/s/crazy-curran-obsg2?file=/src/App.jsx

@mmtmr Your example is still empty. Please make issue reproduction - it will help us to find the problem and fix it.

Снимок экрана 2021-10-20 в 21 40 48

Sorry I also noticed that and was reproducing, I think it should work fine right now here.

mmtmr avatar Oct 20 '21 15:10 mmtmr

@mmtmr Please try [email protected]

dangreen avatar Oct 21 '21 09:10 dangreen

Works perfect . Thanks @dangreen

varun761 avatar Oct 21 '21 18:10 varun761

@mmtmr Please try [email protected]

It works perfectly for me too, thank you!

mmtmr avatar Oct 22 '21 13:10 mmtmr

[email protected]

thanks, this resolved

marioguima avatar Jun 16 '22 15:06 marioguima

"react-chartjs-2": "~5.2.0" I'm having this problem trying to render multiple charts in different tabs. The other tabs are not hidden, they are completely removed from the component tree with conditionals.

I can render all tabs with the same data just fine, but when I change one of the datasets I get:

Canvas is already in use. Chart with ID '0' must be destroyed before the canvas with ID 'Power' can be reused.

I would expect react-chartjs-2 to remove their canvas elements from the page when the react component that creates them is removed from the virtual dom. Is that how it works now or do I need to think about this differently?

ThaJay avatar Mar 27 '23 13:03 ThaJay

Next morning and it got fixed first try. Apparently react-chartjs-2 uses some kind of shallow equality between props of different charts. I had a default dataset for testing of each graph. Once I created a function that spits out a new dataset object every time it instantly worked. (same looking object, just a new reference in memory.)

Maybe this comment will help a future searcher.

ThaJay avatar Mar 28 '23 07:03 ThaJay

how was this problem fixed? can anyone help me since i am facing the same issue.

satakshiBeltech avatar Sep 21 '23 17:09 satakshiBeltech

For me, the issue arose when I used the this method within a callback inside scales/x to truncate some characters from the labels in the options object. image

vosgale avatar Aug 15 '24 03:08 vosgale