Browse Source

Merge pull request #581 from dclause/bugfix/chart

Fix highchart error on update before mounted.
Falko Schindler 2 years ago
parent
commit
bcd916905a
1 changed files with 16 additions and 3 deletions
  1. 16 3
      nicegui/elements/chart.js

+ 16 - 3
nicegui/elements/chart.js

@@ -9,12 +9,25 @@ export default {
       });
     }, 0); // NOTE: wait for window.path_prefix to be set in app.mounted()
   },
+  beforeDestroy() {
+    this.destroyChart();
+  },
+  beforeUnmount() {
+    this.destroyChart();
+  },
   methods: {
     update_chart() {
-      while (this.chart.series.length > this.options.series.length) this.chart.series[0].remove();
-      while (this.chart.series.length < this.options.series.length) this.chart.addSeries({}, false);
-      this.chart.update(this.options);
+      if (this.chart) {
+        while (this.chart.series.length > this.options.series.length) this.chart.series[0].remove();
+        while (this.chart.series.length < this.options.series.length) this.chart.addSeries({}, false);
+        this.chart.update(this.options);
+      }
     },
+    destroyChart () {
+      if (this.chart) {
+        this.chart.destroy()
+      }
+    }
   },
   props: {
     type: String,