-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
120 lines (81 loc) · 3.11 KB
/
main.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
$(document).ready(function(){
// Json data
$.getJSON("https://pomber.github.io/covid19/timeseries.json", function(data){
var country_name;
var confirmed = [];
var recovered = [];
var deceased = [];
var dates = [];
var total_confirmed;
var total_recovered;
var total_deceased;
// On button CLick
$.fn.getInput = function(){
console.log('clicked');
country_name = $("#myInput").val();
console.log(country_name);
country_name = country_name[0].toUpperCase() + country_name.slice(1);
console.log(country_name);
let country_Data = data [country_name];
console.log(data)
let information = country_Data[country_Data.length-1];
console.log(information);
console.log(information['deaths'])
total_confirmed = information['confirmed'];
total_deceased = information['deaths'];
total_recovered = information['recovered'];
//pass data to index.html
$("#confirmed").text(total_confirmed);
$("#deceased").text(total_deceased);
$("#recovered").text(total_recovered);
$.each(country_Data, function(id, obj){
confirmed.push(obj.confirmed);
recovered.push(obj.recovered);
deceased.push(obj.deaths);
dates.push(obj.date);
});
console.log(country_Data);
console.log(confirmed.length);
console.log(recovered.length);
console.log(deceased.length);
dates = dates.slice(Math.max(dates.length - 30, 0));
//Chart
const myChart = document.querySelector('#myChart').getContext('2d');
const chart = new Chart(myChart, {
type: "bar",
data:{
labels: dates ,
datasets:[
{
label:"Confirmed",
//confirmed array
data : confirmed.slice(Math.max(confirmed.length - 30, 0)),
backgroundColor : "#f1c40f",
},
{
label : "Recovered",
data : recovered.slice(Math.max(recovered.length - 30, 0)),
backgroundColor : 'green',
},
{
label : "Deaths/Deceased",
data : deceased.slice(Math.max(deceased.length - 30, 0)),
backgroundColor : 'red',
},
]
},
options: {
},
});
}
$("#myBtn").click(function(){
$.fn.getInput();
});
console.log(data)
// let getInput = function () {
// country_name = document.getElementById("my_input");
// country_name = country_name[0].toUpperCase() + country_name.slice(1);
// console.log(country_name);
// };
});
});