-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Re-rendering plot when any state of the component changes #648
Comments
Yeah, thanks. i will work with it issue. |
@vaasu070 I have released a test package that solves this problem. Could I ask to try it out. And if everything is OK, I will release a minor version with an edit. |
@YakovlevCoded yeah now It is working as expected. Thanks for looking into it. |
@YakovlevCoded , I observed one more issue with test-react-chartjs-2 package, whenever data is updated, the chart fails to show the new data. It is always showing the initial data. This can be observed here . Hope this will be addressed soon. Thanks |
@vaasu070 Thank you! I will work on it. |
@YakovlevCoded A new version 3.0.3 is rolled out, But the above bug still exists in it here. If its not too early to ask, when it will be fixed and released? Its quite critical for out project Thanks. |
@vaasu070 If it's critical I'll try to finish it in the next couple of days. I'll let you know as soon as I'm done with this. |
Would really appreciate this! |
The re-rendering still seems to be an issue on current version 3.0.3. This was not an issue in chart.js v2.9.4 When the state changes the doughnut is redrawn/reanimated. Desired behavior is to rotate the doughnut without redrawing the graph.
|
The above happens on all chart types whether or not the state is passed to the component or not. (in other words, taking rotation out of the options objects still results in the same re-rendering behavior) |
I'm using the following patch as a band-aid until the issue is fixed properly. This probably does not cover all use-cases (it definitely doesn't handle datasets being removed from the chart), but it works for me with a simple bar chart that is refreshed every second: diff --git a/node_modules/react-chartjs-2/dist/index.modern.js b/node_modules/react-chartjs-2/dist/index.modern.js
index f39264d..f8636d6 100644
--- a/node_modules/react-chartjs-2/dist/index.modern.js
+++ b/node_modules/react-chartjs-2/dist/index.modern.js
@@ -117,11 +117,14 @@ var ChartComponent = forwardRef(function (props, ref) {
var _chart$config$data$da = chart.config.data.datasets,
currentDataSets = _chart$config$data$da === void 0 ? [] : _chart$config$data$da;
assign(chart.config.data, newChartData);
- chart.config.data.datasets = newDataSets.map(function (newDataSet) {
+ newDataSets.forEach(function (newDataSet) {
var currentDataSet = find(currentDataSets, function (d) {
return d.label === newDataSet.label && d.type === newDataSet.type;
});
- if (!currentDataSet || !newDataSet.data) return newDataSet;
+ if (!currentDataSet) {
+ currentDataSet = {};
+ currentDataSets.push(currentDataSet);
+ }
if (!currentDataSet.data) {
currentDataSet.data = [];
@@ -130,7 +133,7 @@ var ChartComponent = forwardRef(function (props, ref) {
}
assign(currentDataSet.data, newDataSet.data);
- return _extends({}, currentDataSet, newDataSet, {
+ assign(currentDataSet, newDataSet, {
data: currentDataSet.data
});
}); |
Hi @YakovlevCoded, thanks for all your hard work so far. Is this fix getting close to being released? Critical for our project. |
I'm having same issue. Can I ask about release time ? |
Hi @YakovlevCoded any update on this? |
I have also run into this issue ( I posted about it here: #678 ) |
To add to your observation on |
I am not sure what you mean exactly but I think its an issue with your code - see my working fork here For my patterns issue, I have illustrated it here |
I was saying with
But this is not reflected on the plot. with |
I have a similar issue and am awaiting a conclusion. |
For what its worth I was able to fix the issue (without introducing the patterns bug) by using the fix suggested by @ntamas in this thread. |
Encountered the same problem, it seems quite critical. |
I thought the fix was going to involve a custom build. Once I realized its just patching local node_modules, I realized its not as scary as it looks. Good fix for now! |
Hello, |
@vaasu070 I found how to render with new value.
|
the package worked fine for me with Doughnut and Line charts, thanks! |
I am having a similar issue, where a re-render due to state change on one chart component is causing a re-render on all charts (in their own components) under the same parent component to the parent of the one that had the state change. This is occurring with hover, new data, etc. This did not occur on chart.js versions 2.9.4 and earlier. The resulting animations from the re-render are undesirable and I worry of related performance hits. Is this a related issue to what is being described here? |
Yes, try this package if you can and let people know if it works for you :) |
Very interesting solution by @ntamas. Subscribing to this post to know when this will be merged. Thank you for your hard work, @YakovlevCoded. |
Stacked bar chart is broken as well with test-package. Not rendering any data. With normal package works ok. |
This resolves my issue!
|
This temp solution works for me too, be good to understand why this is happening on the test package and not the original. Thanks |
I was able to fix this going off of @hardy12994's solution:
|
Experiencing the same issue, chart re-renders from scratch on both data changes and parent component re-renders. Seems to be fixed on I am wondering why a relatively critical issue like this hasn't been merged yet. Edit: this happens with newer versions of chart.js as well |
Same problem here. I'm going back to version 2 for the time being. |
|
I'm using chartjs-plugin-zoom for zooming and panning. On zoom or pan events (onZoomComplete and onPanComplete in chartStyle), a function called
|
Hey, is there any update on this issue? Its quite a major problem for us and I'm wondering whether we'll have to switch to using chart.js directly before we go live. Thanks |
@M4sterShake Same here. |
@PCPbiscuit @M4sterShake |
@PCPbiscuit @mssrmaps I've just tried upgrading to 3.0.5 and it fixed the issue for me. If you guys aren't on this version give it a go. Hope it works! |
Just to help clarify things for anyone reading this thread, it looks like this issue is fixed in 3.0.5. @YakovlevCoded it can probably be closed unless anyone has an issue after upgrading to 3.0.5. |
react-chartjs-2@v3.2.0 was released with rerendering improvements. So I'm closing this issue, but feel free to open new ones if any problems appear. |
For me the bug is still alive :( same as previous post says |
@Elius94 Hi. Please open new issue with repoduction. |
Have exact same issue - re-rendering of donut chart when any app state changed. It looks very ugly and distracting. |
@larinius Hi. Please provide issue reproduction. You can fok codesandbox from examples. |
@larinius - this might be a little late - but I just spent a week wracking my brain over performance issues rendering pages with multiple charts with very large datasets constantly re-rendering every time the parent stat changed - slowing down my entire page.... React memo solved my issue - basically made my child components with the chartjs components no re render every time the parent does, only when its down state or props change |
Can you post sample code with useMemo and react-chartjs-2 chart improvements? |
This behaviour was not observed with older version of chartjs. i.e version less than 3.
When ever the state of the component changes , entire plot re renders again as if it is rendering for the first time. sample code to this behaviour is here
The text was updated successfully, but these errors were encountered: