-
Notifications
You must be signed in to change notification settings - Fork 0
/
index3.html
140 lines (126 loc) · 3.75 KB
/
index3.html
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<!DOCTYPE html>
<html>
<head>
<title>Öl-Verbrauch</title>
<!-- Füge Chart.js hinzu -->
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
</head>
<body>
<h1 style="text-align: center; font-family: Arial">Öl-Verbrauch in l</h1>
<!-- Radio-Buttons zur Auswahl der Messreihen -->
<div>
<label>
<input type="radio" name="messreihe" value="Messreihe1" checked />
Messreihe 1
</label>
<label>
</div>
<div style="width: 80%; margin: 0 auto">
<canvas id="oilChart"></canvas>
</div>
<div style="text-align: center; font-family: Arial" id="statistik"></div>
<script>
// Die Daten aus deiner Liste
var messreihen = [
{
name: "Messreihe1",
messpunkte: [
2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
2020, 2021, 2022, 2023,
],
oilLevel: [
2426, 3696, 2703, 3586, 2985, 3036, 3160, 3116, 3232, 3116, 3130,
3132, 3019, 2623,
],
},
{
name: "Messreihe2",
messpunkte: [],
oilLevel: [],
},
{
name: "Messreihe3",
messpunkte: [],
oilLevel: [],
},
{
name: "Messreihe4",
messpunkte: [],
oilLevel: [],
},
{
name: "Messreihe5",
messpunkte: [],
oilLevel: [],
},
{
name: "Messreihe6",
messpunkte: [],
oilLevel: [],
},
//
];
// Funktion zum Aktualisieren des Charts und der Statistik
function updateChart() {
var selectedValue = document.querySelector(
'input[name="messreihe"]:checked'
).value;
var messpunkte, oilLevel;
// Finde die ausgewählte Messreihe
var selectedMessreihe = messreihen.find(function (messreihe) {
return messreihe.name === selectedValue;
});
if (selectedMessreihe) {
messpunkte = selectedMessreihe.messpunkte;
oilLevel = selectedMessreihe.oilLevel;
// Erstelle ein HTML-Canvas-Element für den Chart
var canvas = document.getElementById("oilChart").getContext("2d");
// Erstelle den Balkendiagramm-Chart
if (window.myChart) {
window.myChart.destroy();
}
// Farben für die Balken festlegen (rot für Werte über 300, sonst grün)
var backgroundColor = oilLevel.map((value) =>
value > 300 ? "rgba(255, 99, 132, 0.2)" : "rgba(75, 192, 192, 0.2)"
);
var borderColor = oilLevel.map((value) =>
value > 300 ? "rgba(255, 99, 132, 1)" : "rgba(75, 192, 192, 1)"
);
window.myChart = new Chart(canvas, {
type: "bar",
data: {
labels: messpunkte,
datasets: [
{
label: "Oil in l",
data: oilLevel,
backgroundColor: backgroundColor,
borderColor: borderColor,
borderWidth: 1,
},
],
},
options: {
scales: {
y: {
beginAtZero: true,
suggestedMax: 3500,
},
},
plugins: {
legend: false,
},
},
});
}
}
// Führe die Aktualisierung beim Laden der Seite und bei Änderungen der Auswahl durch
updateChart();
document
.querySelectorAll('input[name="messreihe"]')
.forEach(function (radio) {
radio.addEventListener("change", updateChart);
});
</script>
</body>
</html>