-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
100 lines (78 loc) · 2.84 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
$(document).ready(function(){
//For Worldwide Details
init()
function init(){
var urlG = "https://api.covid19api.com/summary"
var dataG = ''
$.get(urlG, function(dataG){
console.log(dataG.Global)
dataG = `
<td style="font-size: 18px;" class="text-warning">${dataG.Global.TotalConfirmed}</td>
<td style="font-size: 18px;" class="text-info">${dataG.Global.NewConfirmed}</td>
<td style="font-size: 18px;" class="text-success">${dataG.Global.TotalRecovered}</td>
<td style="font-size: 18px;" class="text-danger">${dataG.Global.TotalDeaths}</td>
`
$("#globe").html(dataG)
})
}
//For India Details
var url = "https://api.covid19india.org/data.json"
$.getJSON(url, function(data){
console.log(data)
var total_active, total_recovered, total_deaths, total_confirmed
var state = []
var confirmed = []
var recovered = []
var deaths = []
$.each(data.statewise, function(id,obj){
state.push(obj.state)
confirmed.push(obj.confirmed)
recovered.push(obj.recovered)
deaths.push(obj.deaths)
})
// console.log(state)
//Remove the 0th Element 'Total Cases' using shift()
state.shift()
confirmed.shift()
recovered.shift()
deaths.shift()
console.log(state)
total_active = data.statewise[0].active
total_confirmed = data.statewise[0].confirmed
total_recovered = data.statewise[0].recovered
total_deaths = data.statewise[0].deaths
$("#active").append(total_active)
$("#confirmed").append(total_confirmed)
$("#recovered").append(total_recovered)
$("#deaths").append(total_deaths)
var myChart = document.getElementById("myChart").getContext('2d')
var ctx = document.getElementById("myChart");
ctx.height = 180;
var chart = new Chart(myChart,{
type:'line',
data:{
labels:state,
datasets:[
{
label: "Confirmed Cases",
data: confirmed,
backgroundColor: "#ffce56",
minBarLength: 100
},
{
label: "Recovered Cases",
data: recovered,
backgroundColor: "#00cc66",
minBarLength: 100
},
{
label: "Decreased",
data: deaths,
backgroundColor: "#ff6384",
minBarLength: 100
},
]
},
})
})
})