-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindia.js
101 lines (87 loc) · 2.49 KB
/
india.js
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
url = "https://api.covid19india.org/data.json"
async function getData(url){
response = await fetch(url)
data = await response.json()
return data
}
generalise_data = (data) => {
total_confirmed = []
total_deaths = []
total_recovered = []
dates = []
for(i = 0; i < data.length; i++){
day = data[i]
total_confirmed.push(parseInt(day["totalconfirmed"]))
total_deaths.push(parseInt(day["totaldeceased"]))
total_recovered.push(parseInt(day["totalrecovered"]))
dates.push(day["date"])
}
generalised = {
"totalConfirmedCases": total_confirmed,
"totalDeaths": total_deaths,
"totalRecoveredCases": total_recovered,
"dates": dates
}
return generalised
}
prepareXlabels = (data) => {
xlabels = []
for(i = 0; i < data.length; i++){
xlabels.push(i+1)
}
return xlabels
}
drawGraph = (data) => {
canvas = document.getElementById("graph")
var ctx = canvas.getContext('2d');
confimredDataset = {
label: '# of Confirmed Cases',
data: data["totalConfirmedCases"],
backgroundColor:
'rgba(54, 162, 235, 0.2)',
borderColor:
'rgba(54, 162, 235, 1)',
borderWidth: 1,
fill: false
}
deathsDataset = {
label: "#of deaths",
data: data["totalDeaths"],
backgroundColor:
'rgba(255, 9, 12, 0.2)',
borderColor:
'rgba(255, 9, 12, 1)',
borderWidth: 1,
fill: false
}
recoveredDataset = {
label: "#of recovered Cases",
data: data["totalRecoveredCases"],
backgroundColor:
'rgba(0, 170, 0, 0.2)',
borderColor:
'rgba(0, 175, 0, 1)',
borderWidth: 1,
fill: false
}
graph = new Graph(ctx, 'bar')
graph.setLabels(data["dates"])
graph.addDataset(confimredDataset)
graph.addDataset(deathsDataset)
graph.addDataset(recoveredDataset)
// graph.show()
var myChart = graph.plot()
myChart.canvas.parentNode.style.height = '680px';
myChart.canvas.parentNode.style.width = '1240px';
}
dataPromise = getData(url)
dataPromise.then(data => {
time_series = data['cases_time_series']
time_series = generalise_data(time_series)
// console.log(time_series, xlabels)
drawGraph(time_series)
// statewise_data = data['statewise']
// tested_data = data['tested']
}).catch(err => {
console.log(err)
})