diff --git a/web/newWebsite/graph-classes.js b/web/newWebsite/graph-classes.js index 4bacf78..8c90a2e 100644 --- a/web/newWebsite/graph-classes.js +++ b/web/newWebsite/graph-classes.js @@ -136,29 +136,32 @@ class DataProcessor { // You can add more filtering methods based on different criteria if needed update(data) { this.data = data; + this.graph; console.log("Data updated"); console.log(data); } - graph() { + makeGraph() { let div = document.createElement("div"); div.setAttribute("id", "graph1"); document.body.appendChild(div); - let graph = new Graph(1); - graph.makeGraph("temp", "red", "Temperature"); - graph.makeGraph("humi", "blue", "Humidity"); - graph.makeGraph("eco2", "green", "eCO2"); - graph.makeGraph("tvoc", "#F5G644", "TVOC"); + this.graph = new Graph(1); + this.graph.makeGraph("temp", "red", "Temperature"); + this.graph.makeGraph("humi", "blue", "Humidity"); + this.graph.makeGraph("eco2", "green", "eCO2"); + this.graph.makeGraph("tvoc", "#F5G644", "TVOC"); + } - graph.updateData(this.data[0].Type, this.data[0].Value); + updateGraph() { + this.graph.updateData(this.data[0].Type, this.data[0].Value); console.log(this.data[0].Type, this.data[0].Value); - graph.updateData(this.data[1].Type, this.data[1].Value); + this.graph.updateData(this.data[1].Type, this.data[1].Value); console.log(this.data[1].Type, this.data[1].Value); - graph.updateData(this.data[2].Type, this.data[2].Value); + this.graph.updateData(this.data[2].Type, this.data[2].Value); console.log(this.data[2].Type, this.data[2].Value); - graph.updateData(this.data[3].Type, this.data[3].Value); + this.graph.updateData(this.data[3].Type, this.data[3].Value); console.log(this.data[3].Type, this.data[3].Value); - graph.updateGraph(); + this.graph.updateGraph(); } } diff --git a/web/newWebsite/graph-main.js b/web/newWebsite/graph-main.js index c271e48..8f2de1d 100644 --- a/web/newWebsite/graph-main.js +++ b/web/newWebsite/graph-main.js @@ -119,17 +119,12 @@ function fetchData() { .then((data) => { createFilterContainer(); processor.update(data); - processor.graph(); + processor.makeGraph(); + processor.updateGraph(); }) .catch((error) => { console.error("Error fetching data:", error); }); } -fetchData(); - -// Function to create the graph -function createGraph() { - const graph = new Graph("graph"); - graph.updateGraph(); -} \ No newline at end of file +fetchData(); \ No newline at end of file