-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph-unlinked.html
108 lines (91 loc) · 3.1 KB
/
graph-unlinked.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
<!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 (No Longer In Used)</h1>
<h5 style="color: red">DISCLAIMER: UNLINK DATA MAYBE WRONG DUE TO NATURE OF DATA UPDATE. USE <a href="./graph" target="_self" rel="noopener noreferrer" style="color:lightblue ">THIS</a> INSTEAD <div class="date" style="color:white"></div></h5>
<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>
const date = document.querySelector('.date');
fetch("https://liang-zhengxin.github.io/SG-COVIDdata/data/dailyLocalUnlinkCases.json")
.then(response => response.json())
.then(data=> {addUnlink(data)});
function addUnlink(data) {
var xValues = []
var yValues = []
for (const [key, value] of Object.entries(data)) {
xValues.push(key)
yValues.push(value)
console.log(`${key}: ${value}`);
}
console.log(yValues.length)
console.log(yValues)
const t = Object.keys(data)[0]
date.textContent = "Updated: " + t
globalThis.UnlinkxValues30 = xValues.slice(0,31).reverse()
globalThis.UnlinkyValues30 = yValues.slice(0,31).reverse()
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);
}
var xValues30 = xValues.slice(0,31).reverse()
var yValues30 = yValues.slice(0,31).reverse()
new Chart("myChart", {
type: "line",
data: {
labels: xValues30,
datasets: [{
label: "Total",
fill: false,
lineTension: 0,
backgroundColor: "rgba(255,0,0,1.0)",
borderColor: "rgba(255,0,100,0.8)",
data: yValues30
},
{
label: "Unlinked",
fill: false,
lineTension: 0,
backgroundColor: "rgba(255,255,0,1.0)",
borderColor: "rgba(255,255,100,0.8)",
spanGaps: true,
data: UnlinkyValues30
}]
},
options: {
legend: {display: true,position:'bottom',align:"start"},
scales: {
yAxes: [{ticks: {min: 0, max:Math.max(...yValues30)+10, fontColor: "white"}}]
}
}
});
}
</script>
</body>
</html>