amcharts5 icon indicating copy to clipboard operation
amcharts5 copied to clipboard

In React JS graph gets redrawn whenever data changes in useEffect

Open AbhishekDigitalSalt opened this issue 1 year ago • 5 comments

I am implementing am chart in React JS. To update the chart we need to update the state as per react architecture, and whenever I update the state with new data, useLayoutEffect runs again and whole chart gets redrawn. Is there any way to prevent redrawing of whole chart in React JS?

AbhishekDigitalSalt avatar Jul 21 '22 09:07 AbhishekDigitalSalt

Are you creating the whole chart in useLayoutEffect? You should only update changes in it:

https://www.amcharts.com/docs/v5/getting-started/integrations/react/#Using_with_hooks

martynasma avatar Jul 21 '22 10:07 martynasma

in useEffect create one dependency and if that dependency gets change you will update the chart by first disposing the chart and creating it right.

shanqq avatar Jul 21 '22 11:07 shanqq

in useEffect create one dependency and if that dependency gets change you will update the chart by first disposing the chart and creating it right. yes. but whenever dependency updates charts gets redrawn with new values. but I don't want it to get redrawn on every update.

AbhishekDigitalSalt avatar Jul 21 '22 11:07 AbhishekDigitalSalt

but the data is getting change right then how you will get that done. by not redrawing that part.

shanqq avatar Jul 21 '22 12:07 shanqq

maybe you can do if the root is there then don't dispose ?? am5.array.each(am5.registry.rootElements, function (root) { if ((root == null)) { root.dispose() } })

shanqq avatar Jul 21 '22 12:07 shanqq

This issue is stale because it has been open 30 days with no activity. It will be closed in 5 days unless a new comment is added.

github-actions[bot] avatar Aug 21 '22 00:08 github-actions[bot]