Update infinite loop or no chart update
See original GitHub issueExpected Behavior
No error, and update chart.
Actual Behavior
Update chart, but an error:
vue.esm.js:628 [Vue warn]: You may have an infinite update loop in watcher with expression "chartData"
I have read #487 and #518 and #416 for try fix this, and #44 but without success. If i juste use reactiveProps without update metohd, my chart dont update ;c
My actually chart code:
<script>
import 'chartjs-adapter-moment';
import { Line, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins;
export default {
extends: Line,
mixins: [reactiveProp],
props: ['options', 'newData'],
mounted () {
this.renderChart(this.chartData, this.options);
},
watch: {
chartData: {
deep: true,
handler: function () {
this.renderChart(this.chartData, this.options);
//this.$data._chart.update();
}
}
}
}
</script>
And method to push data:
var oldStas = instance.data_graphe;
oldStas.labels.push(new Date(Date.now()));
//On insére les valeur de la ram avec la date dans le tableau
oldStas.datasets[0].data.push({
x: new Date(Date.now()),
y:memory
});
//On insére les valeur du cpu avec la date dans le tableau
oldStas.datasets[1].data.push({
x: new Date(Date.now()),
y: cpu
});
if (oldStas.datasets[0].data.length > 30)
oldStas.datasets[0].data.splice(0, 1);
if (oldStas.datasets[1].data.length > 30)
oldStas.datasets[1].data.splice(0, 1);
instance.data_graphe = oldStas;
I have tried without oldStats variable, but no work.
Environment
- vue.js version: 2.6.11
- vue-chart.js version: 3.5.0
- npm version: 6.14.4
For 2 days I have been looking for all possible solutions, but can’t find any that work.
Thank you for making this vuejs “plugin” it is a very good plugins, and thank you for the help you would bring me! Sorry for my bad english ;c
Issue Analytics
- State:
- Created 3 years ago
- Comments:13 (4 by maintainers)
Top Results From Across the Web
[Vue warn]: You may have an infinite update loop in watcher ...
On data change, it will either call update() if only the data inside the datasets has changed or renderChart() if new datasets were...
Read more >Infinite loop is occuring when trying to update a row in ... - MSDN
As prabhakarbn says, no need to do UpdateRow there. The theory behind it: The Updating event fires as a part of the execution...
Read more >[Solved]-How to avoid infinite loop while updating self in a ...
Coding example for the question How to avoid infinite loop while updating ... You can update it by taking only one(latest) value from...
Read more >JavaScript while Loop - W3Schools
Loops can execute a block of code as long as a specified condition is true. The While Loop. The while loop loops ......
Read more >Loops in Java - GeeksforGeeks
There is no checking of any condition for the first time. After the execution of the statements, ... infinite loop because update statement....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I had the same problem but kinda fixed it with with a custom watcher (without mixins) using a support boolean to execute the update only once per watch trigger. NB: the nextTick is the reason it works, and that’s also a better solution than a setTimeout.
I still need to test if better, but the infinite loop seems to be gone.
PS: I’ve also tried using lodash to compare newVal with oldVal without success, and was also time consuming
Removing mixins.reactiveProp and setting a deep watch to chartData for renderChart() worked for me. My infinite loop came from setting values for chartjs-annotation-plugin to the chart’s options.
As @ph1823 mentioned, using the reactiveProp worked fine in local environment but browser became unresponsive in dev environment. I didn’t find the inifinite loop warning until I removed the plugin code because this was a base component shared with other chart components.
I’m on vue 2.6.14 and vue-chartjs 3.5.1 and chartjs-plugin-annotation 0.5.7.