-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
65 lines (50 loc) · 2.3 KB
/
index.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
// eslint-disable-next-line no-undef
const stateWiseCovid19 = new StateCovidChart();
const deathCount = document.getElementById('death-count');
const deathCaseDelta = document.getElementById('death-delta');
const recoveryCaseCount = document.getElementById('recovery-count');
const recoveredCaseDelta = document.getElementById('recovered-delta');
const confirmedCaseDelta = document.getElementById('confirmed-delta');
const confirmedCaseCount = document.getElementById('confirmed-count');
const activeCaseCount = document.getElementById('active-count');
function getChartData() {
const stateWiseDiv = document.getElementById('state-covid19-stats').getContext('2d');
const stateCovidDataSet = stateWiseCovid19.getChartData();
console.log(stateCovidDataSet);
stateCovidDataSet.then((covid19StateData) => {
deathCount.innerText = covid19StateData.totalDeaths;
deathCaseDelta.innerText = `+${covid19StateData.deltaCumulativeValue.deceaseddelta}`;
recoveryCaseCount.innerText = covid19StateData.totalRecovered;
recoveredCaseDelta.innerText = `+${covid19StateData.deltaCumulativeValue.recovereddelta}`;
confirmedCaseCount.innerText = covid19StateData.totalConfirmed;
confirmedCaseDelta.innerText = `+${covid19StateData.deltaCumulativeValue.confirmeddelta}`;
activeCaseCount.innerText = covid19StateData.totalActiveCases;
const stateNamesList = covid19StateData.statList.filter(value => value.confirmedCase > 2).map((value) => value.stateName);
const confirmedCaseForStates = covid19StateData.statList
.filter(value => value.confirmedCase > 2)
.map(value => value.confirmedCase);
// eslint-disable-next-line no-undef,no-unused-vars
const chart = new Chart(stateWiseDiv, {
type: 'bar',
data: {
labels: stateNamesList,
datasets: [{
label: 'Total Cases',
data: confirmedCaseForStates,
backgroundColor: 'rgb(255, 99, 132)',
borderColor: 'rgb(255, 99, 232)',
}],
},
options: {
responsive: true,
scales: {
xAxes: [{
categoryPercentage: 0.3,
barPercentage: 0.6,
}]
}
},
});
}).catch((error) => console.log(error));
}
getChartData();