-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
41 lines (38 loc) · 1.16 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<title>Elpriser charting test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<p>
<button id="down"><</button>
<input type="date" id="dateSelector">
<button id="up">></button>
</p>
<canvas id="canvas" width="800" height="500"></canvas>
<script src="https://cdn.jsdelivr.net/npm/chart.js@3/dist/chart.min.js"></script>
<script type="module">
import getData from './src/energidataservice.mjs';
import drawChart from './src/chart.mjs';
dateSelector.value = new Date().toISOString().substring(0, 10);
dateSelector.max = dateSelector.value;
down.addEventListener('click', () => {
dateSelector.stepDown();
draw();
});
up.addEventListener('click', () => {
dateSelector.stepUp();
draw();
});
async function draw() {
const data = await getData(dateSelector.value, 'DK2');
if (data) {
drawChart(canvas, dateSelector.value, 'DK2', data);
}
}
dateSelector.addEventListener('change', draw);
draw();
</script>
</body>
</html>