-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
210 lines (163 loc) · 5.68 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>COVID-19 Tracker</title>
<link rel="stylesheet" href="main.css">
<script src="jquery-3.5.1.min.js"></script>
<script src="Chart.bundle.js"></script>
<script src="script.js"></script>
<link href="https://fonts.googleapis.com/css2?family=Roboto&display=swap" rel="stylesheet">
<link rel="shortcut icon" href="favicon.png">
</head>
<body>
<div class="tracker-container">
<p class="state"></p>
<p class="positive"></p>
<p class="incPos"></p>
<p class="totalTests"></p>
<p class="recordNew"></p>
</div>
<canvas id="myChart" width="100" height="30"></canvas>
<script>
var state = prompt("Please enter a state's lowercase initials (ex: az, co , ny)");
//-----------Grab Graph Data----------------------
var collectedData = [];
var collectedLabels = [];
var barData = [];
var testingData = [];
var marchFixDate = "3/";
var concatDate = 5;
var totalAdjustForMax;
var recordNumber = 0;
$.getJSON("https://api.covidtracking.com/v1/states/" + state + "/daily.json",
function(graphData){
var cap = graphData.length - 1;
var target;
for(let x in graphData){
target = cap-x;
collectedData.push(graphData[target].positive - graphData[target].recovered - graphData[target].death);
barData.push(graphData[target].positiveIncrease);
testingData.push(graphData[target].totalTestResultsIncrease);
if (graphData[target].positiveIncrease > recordNumber){
recordNumber = graphData[target].positiveIncrease;
}
//-------------Date---------
var date = graphData[target].date.toString();
date = date.slice(4,6) + "/" + date.slice(6,8) + "/" + date.slice(0,4);
collectedLabels.push(date);
totalAdjustForMax = graphData[target].positive - graphData[target].recovered - graphData[target].death;
}
$(".recordNew").append("<b>Most Cases in One Day: </b>" + recordNumber.toLocaleString());
})
//-------------------------------------------------
Chart.defaults.global.defaultFontColor = "#fff";
var ctx = document.getElementById('myChart').getContext('2d');
var myChart = new Chart(ctx, {
type: 'line',
data: {
labels: collectedLabels,
datasets: [{
label: '# of Current Cases',
data: collectedData,
lineTension: 0,
fill: false,
backgroundColor: [
'rgba(255, 99, 132, 0.2)',
'rgba(54, 162, 235, 0.2)',
'rgba(255, 206, 86, 0.2)',
'rgba(75, 192, 192, 0.2)',
'rgba(153, 102, 255, 0.2)',
'rgba(255, 159, 64, 0.2)'
],
borderColor: [
'rgba(255, 99, 132, 1)',
'rgba(54, 162, 235, 1)',
'rgba(255, 206, 86, 1)',
'rgba(75, 192, 192, 1)',
'rgba(153, 102, 255, 1)',
'rgba(255, 159, 64, 1)'
],
borderWidth: 2,
type: 'line',
pointBackgroundColor: "red"
}, {
label: '# of New Diagnoses',
data: barData,
type: 'bar',
order: 1,
backgroundColor: "green"
},{
label: '# of New Tests',
data: testingData,
type: 'line',
order: 1,
backgroundColor: "orange",
fill: false,
borderWidth: 1,
lineTension: 0,
borderColor: "orange",
}]
},
options: {
fill: false,
tooltips: {
mode: "index"
},
responsive: true,
maintainAspectRatio: true,
title: {
text: "Current Cases Since the Beginning of the Pandemic in Indiana",
display: true,
},
scales: {
yAxes: [{
gridLines: {
color: 'grey'
},
ticks: {
beginAtZero: true,
stepSize: 5000,
max: totalAdjustForMax,
min: 0,
}
}],
xAxes: [{
gridLines: {
color: 'grey'
},
ticks: {
autoSkip: true,
maxTicksLimit: 20
}
}],
}
}
});
$.getJSON("https://api.covidtracking.com/v1/states/" + state + "/current.json",
function(data){
//console.log(data);
var state = data.state;
var lastupdate = data.lastUpdateEt;
var positive = data.positive - data.recovered - data.death;
var incPos = data.positiveIncrease;
var totalTests = data.totalTestResults;
var currHospital = data.hospitalizedCurrently;
var incHospital = data.hospitalizedIncrease;
$(".state").append("<b>State: </b>" + state);
$(".lastupdate").append("<b>Last Updated: </b>" + lastupdate);
$(".positive").append("<b>Positive: </b>" + positive.toLocaleString());
$(".incPos").append("<b>Latest New Cases in a Day: </b>" + incPos.toLocaleString());
$(".totalTests").append("<b>Total Tests Conducted: </b>" + totalTests.toLocaleString());
$(".currHospital").append("<b>Current Hospital Cases: </b>" + currHospital.toLocaleString());
$(".incHospital").append("<b>Latest New Hospital Cases: </b>" + incHospital.toLocaleString());
})
</script>
<div class="hospital-container">
<p><b>Hospital Data</b></p>
<p class="currHospital"></p>
<p class="incHospital"></p>
</div>
<footer class="lastupdate"></footer>
</body>
</html>