let data; let measurements; let date; let value; let newArrayTemp = []; let newArrayHumid = []; let newArrayLight = []; let timeArray = []; // Array to store time values let dateArray = [1, 2, 3]; let valueArray = [1, 2, 3, 4, 5]; let valueArray2 = [1, 2, 3, 4, 5]; let valueArray3 = [1, 2, 3, 4, 5]; let valueArray4 = [1, 2, 3, 4, 5]; let newValueArray = [4, 5, 6]; let myValue = 1; let intervalDelay = 50; class liveGraph { constructor() { this.timeArray = []; this.dateArray = []; this.valueArray = []; } pushArray(array) { for (let i = 0; i < 10; i++) { array.push(Math.random() * 10); } } makeGraph() { Plotly.plot("liveGraph", [ { x: this.timeArray, // Use timeArray as x values y: this.valueArray, mode: "lines", line: { color: "#80CAF6" }, name: "Temperature", }, ]); } updateGraph() { let cnt = 0; let interval = setInterval(function () { var time = new Date(); this.timeArray.push(new Date()); this.pushArray(this.valueArray); var update = { x: [[this.timeArray]], y: [[this.newValueArray]], }; var olderTime = time.setMinutes(time.getMinutes() - 1); var futureTime = time.setMinutes(time.getMinutes() + 1); var minuteView = { xaxis: { type: "date", range: [olderTime, futureTime], }, }; Plotly.relayout("liveGraph", minuteView); if (cnt === 10) clearInterval(interval); }, intervalDelay); } } let graph = new liveGraph(); graph.makeGraph(); graph.updateGraph(); graph.pushArray(); console.log("test");