diff --git a/web/js-ts/serialv2.js b/web/js-ts/serialv2.js index 2f7c93e..5ab5a3c 100644 --- a/web/js-ts/serialv2.js +++ b/web/js-ts/serialv2.js @@ -72,25 +72,9 @@ async function readLoop() { document.getElementById("humid").innerHTML = SensorValues[1]; document.getElementById("licht").innerHTML = SensorValues[2]; - Plotly.newPlot('tempGraph', [{ - y: tempArray, - - mode: 'lines', - line: {color: '#80CAF6'} - }]); - Plotly.newPlot('humidGraph', [{ - y: humidArray, - - mode: 'lines', - line: {color: '#80CAF6'} - }]); - Plotly.newPlot('lightGraph', [{ - y: lichtArray, - - mode: 'lines', - line: {color: '#80CAF6'} - }]); - + plotly(tempGraph, tempArray) + plotly(humidGraph, humidArray) + plotly(lightGraph, lichtArray) } // Show the received data in the console @@ -106,14 +90,17 @@ async function readLoop() { } } -async function plotly(){ - Plotly.update(tempgraph, {x: [xArray], y: [tempArray] }) - -} - // Close the port async function disconnect() { await reader.cancel(); await port.close(); console.log("Port is closed!"); +} + +function plotly(graph, array){ + Plotly.newPlot(graph, [{ + y: array, + mode: 'lines', + line: {color: '#80CAF6'} + }]); } \ No newline at end of file