-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
97 lines (97 loc) · 2.83 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const canvas = document.getElementById("wphcanv").getContext("2d");
var Chartdata;
const lineColor = "rgba(0,77, 165)";
var wphChart = new Chart(canvas, {
type: 'line',
data: {
labels: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
datasets: [{
label: 'WpH (Watts per hour)',
data: [],
backgroundColor: lineColor,
borderColor: [
'rgba(0,0,0,1)',
'rgba(0,0,0,1)',
'rgba(0,0,0,1)',
'rgba(0,0,0,1)',
'rgba(0,0,0,1)',
'rgba(0,0,0,1)',
'rgba(0,0,0,1)'
],
borderWidth: 0,
pointBackgroundColor: [],
pointBorderColor: [],
pointBorderWidth: 1,
}]
},
options: {
plugins: {
legend: {
labels: {
font: {
size: 12,
family: 'Monospace Regular',
}
}
}
},
responsiveAnimationDuration: 1000,
elements: {
point: {
pointStyle: 'circle',
rotation: 45,
radius: 3,
},
line: {
cubicInterpolationMode: 'monotone',
steppedLine: 'before'
}
},
scales: {
yAxes: [{
ticks: {
max: 100,
stepSize: 5,
maxTicksLimit: 100,
suggestedMin: 0,
beginAtZero: true,
fontColor: 'rgba(218, 55, 55)',
fontSize: 20,
fontFamily: "Monospace Regular",
}
}],
xAxes: [{
ticks: {
fontColor: 'rgba(218, 39, 39)',
fontFamily: "Monospace Regular",
fontSize: 20,
}
}]
},
},
});
start();
async function start() {
var CurrYear = new Date().getYear();
var month = new Date().getMonth() + 1;
document.getElementById("signature").innerHTML = `<strong> ${1900 + CurrYear} Christian Hozak</strong>`
document.title = "Sundata " + new Date().getFullYear() + "/" + month + "/" + new Date().getDate();
Chartdata = await fetch("/Backend/data.json").then(res => res.json()).then(data => Chartdata = data).catch(error => console.log(error));
setupCharts();
return;
}
function setupCharts() {
//setting the colors
var maxIndex = wphChart.data.labels.length;
for(var i = 0; i < maxIndex; i++) {
wphChart.data.labels[i] = Chartdata[i].Time;
wphChart.data.datasets[0].pointBorderColor[i] = lineColor;
}
for (var i = 0; i < 7; i++) {
if (i > 6) {
return;
}
wphChart.data.datasets[0].data[i] = Chartdata[i].wph;
}
wphChart.update();
}