From b4c5b687a8bdbdc41239afbc8fd8cd86bb42834b Mon Sep 17 00:00:00 2001
From: Tor-Einar Skog <tor-einar.skog@nibio.no>
Date: Fri, 15 Sep 2023 08:35:06 +0200
Subject: [PATCH] Recreate chart on subsequent model runs

---
 ipmd/templates/ipmd/saddlegallmidgeform.html | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/ipmd/templates/ipmd/saddlegallmidgeform.html b/ipmd/templates/ipmd/saddlegallmidgeform.html
index ae1b580c..cc2e680c 100644
--- a/ipmd/templates/ipmd/saddlegallmidgeform.html
+++ b/ipmd/templates/ipmd/saddlegallmidgeform.html
@@ -99,6 +99,9 @@
     var selectList = document.getElementById("weatherStationId");
     
     var weatherData = undefined;
+
+    // Object that will hold the chart. Must be destroyed and recreated if you run the model more than once
+    let resultChart = undefined;
     
     async function initPage() {
         currentModelMetaData = await getModelMetadata("adas.dss","HAPDMA");
@@ -505,7 +508,11 @@
 
         const ctx = document.getElementById('resultChart');
 
-        new Chart(ctx, {
+        if(resultChart !== undefined)
+        {
+            resultChart.destroy();
+        }
+        resultChart = new Chart(ctx, {
             type: "line",
             options: {
                 responsive: true,
-- 
GitLab