-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.html
67 lines (62 loc) · 1.85 KB
/
graph.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
<!DOCTYPE html>
<html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.4/Chart.js"></script>
<style>
body {
color: #fafafa;
background-color: #202731;
font-family: "Times New Roman";
}
.footer {
position: fixed;
left: 1.5vw;
bottom: 0;
width: 100%;
font-size:2vh;
color: white;
text-align: left;
}
</style>
<body>
<h1>Locally Transmitted Cases</h1>
<canvas id="myChart" style="width:8vw;height:5vh;position:fixed;top: 50%;left: 50%;transform: translate(-50%, -50%)"></canvas>
<div class="footer">
<p>Source: <a href="https://www.moh.gov.sg/news-highlights" target="_blank" rel="noopener noreferrer" style="color:whitesmoke">MOH Press Release</a> <a href="./index" target="_self" rel="noopener noreferrer" style="color:whitesmoke">Vaccination Data</a></p>
</div>
<script>
fetch("https://liang-zhengxin.github.io/SG-COVIDdata/data/dailyLocalCases.json")
.then(response => response.json())
.then(data=> {show(data)});
function show(data) {
var xValues = []
var yValues = []
for (const [key, value] of Object.entries(data)) {
xValues.push(key)
yValues.push(value)
console.log(`${key}: ${value}`);
}
var xValues30 = xValues.slice(0,31).reverse()
var yValues30 = yValues.slice(0,31).reverse()
new Chart("myChart", {
type: "line",
data: {
labels: xValues30,
datasets: [{
fill: false,
lineTension: 0,
backgroundColor: "rgba(255,0,0,1.0)",
borderColor: "rgba(255,0,100,0.8)",
data: yValues30
}]
},
options: {
legend: {display: false},
scales: {
yAxes: [{ticks: {min: 0, max:Math.max(...yValues30), fontColor: "white"}}]
}
}
});
}
</script>
</body>
</html>