forked from as1605/DevClub-Assignment4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
83 lines (83 loc) · 3.19 KB
/
script.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
var todconf;
var totconf;
var todconfi;
var totconfi;
var label=[]
var data1=[]
var data2=[]
chartIt();
async function chartIt(){
await loadNames();
const ctx = document.getElementById('myChart');
const myChart = new Chart(ctx, {
type: 'line',
data: {
labels: label,
datasets: [{
label: 'NUMBER OF CONFIRMED CASES IN INDIA OVER THE LAST 30 DAYS',
data: data1,
borderWidth: 1,
borderColor: "blue",
backgroundColor: "white"
}]
},
options: {
legend: {
labels: {
fontColor: "white",
fontSize: 18
}
},
scales: {
yAxes:
[{
ticks: {
fontColor: "#FFF",
fontSize: 18,
stepSize: 1,
beginAtZero: true
}
}],
xAxes: [{
ticks: {
fontColor: "#FFF",
fontSize: 14,
stepSize: 1,
beginAtZero: true
}
}]
}
}
})
};
async function loadNames() {
const response = await fetch('https://api.covid19api.com/total/dayone/country/india');
const response2 = await fetch ('https://api.covid19api.com/summary')
const obj = await response.json();
const obj2= await response2.json();
todconf=obj2.Global.NewConfirmed;
totconf=obj2.Global.TotalConfirmed;
console.log(totconf);
console.log(todconf);
todconfi=obj2.Countries[77].NewConfirmed;
totconfi=obj2.Countries[77].TotalConfirmed;
function myFunction() {
document.getElementById("todglob").innerHTML = todconf;
document.getElementById("totglob").innerHTML = totconf;
document.getElementById("todind").innerHTML = todconfi;
document.getElementById("totind").innerHTML = totconfi;
}
myFunction();
var res = [];
for(var i in obj)
res.push(obj[i]);
let total=0;
let need = res.slice((res.length - 31), res.length)
for(let i=1;i<31;i++){
var date = new Date(need[i].Date);
label.push(date.toISOString().substring(0, 10))
data1.push(need[i].Confirmed-need[i-1].Confirmed)
}
console.log(label)
console.log(data1)
}