Hello:
I recently updated my flows from Dashboard1 to Dashboard2. In the process I migrated all my charts to chart.js (I already had some in DB1 but had others that were native DB1 charts). And because I’m a sucker for punishment, after getting all the chart.js charts working, I also converted them to eCharts! All this was with a lot of trial and error and help from ChartGPT/Gemini AI as I have no knowledge of vue/limited html and CSS (just enough to meet my needs).
All charts are working as expected, but I am now seeing MaxListenersExceededWarning (s) in the Node-RED log and I’m wondering if this is related to my ui-template code. Below is the section of the code that is pretty much the same for all the charts (total of 10-12) of them on different ui-pages.
export default {
data() {
return {
myChart: null,
resizeHandler: null,
};
},
//---Watch Section---
watch: {
msg: function () {
if (this.msg && this.msg.topic === "data" && this.myChart && this.msg.payload && this.msg.payload.labels) {
const p = this.msg.payload;
this.update(p.labels, p, this.msg.title,this.msg.legend); // remember to add back this.msg.colors
}
}
},
//---Mounted Section---
mounted() {
this.$nextTick(() => {
const ready = setInterval(() => {
const container = this.$refs.charttpw33;
if (window.echarts && container && container.offsetWidth > 0 && container.offsetHeight > 0) {
clearInterval(ready);
this.init();
if (this.msg && this.msg.topic === "data" && this.msg.payload) {
const p = this.msg.payload;this.update(p.labels, p, this.msg.title,this.msg.legend); /*remember to add back this.msg.colors*/
}
this.resizeHandler = () => { if (this.myChart) this.myChart.resize(); };
window.addEventListener('resize', this.resizeHandler);
setTimeout(() => { if (this.myChart) this.myChart.resize(); }, 300);
}
}, 100);
});
},
//---Before Destroy Section---
beforeDestroy() {
if (this.myChart) {
this.myChart.dispose();
}
if (this.resizeHandler) {
window.removeEventListener('resize', this.resizeHandler);
}
},
In reading the Flowfuse documentation, it appears that beforeDestroy() is not one of the supported VueJS API and may be causing the listeners to remain open? Should this be replaced by unmounted()? Any other suggestions for improvement would also be really appreciated. Thanks for your help.