This repository has been archived by the owner on Apr 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
135 lines (121 loc) · 3.54 KB
/
app.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
const vm = new Vue({
el: '#app',
data: {
results: [],
chartsdata: [],
displaydays: 7,
},
methods: {
newDate: function (d) {
return moment().add(d, 'd')
},
updateDisplay: function (days) {
this.displaydays = days
axios.get('https://api.covid19india.org/data.json').then((response) => {
this.results = response.data.statewise
this.chartsdata = response.data.cases_time_series.reverse()
const startDate = moment()
.subtract(this.displaydays, 'days')
.format('DD MMMM')
const chartDisplay = this.chartsdata
.filter((d, i) => moment(d.date).isSameOrAfter(startDate))
.sort((a, b) => moment(a.date) - moment(b.date))
const dailyConfirmed = chartDisplay.map((d) => d.dailyconfirmed)
const dailyRecovered = chartDisplay.map((d) => d.dailyrecovered)
const labels = chartDisplay.map((d) => d.date)
window.myLine.data.labels = labels
window.myLine.data.datasets = [
{
label: 'New cases',
backgroundColor: '#E64A35',
borderColor: '#E64A35',
data: dailyConfirmed,
fill: false,
},
{
label: 'New recoveries',
fill: false,
backgroundColor: 'green',
borderColor: 'green',
data: dailyRecovered,
},
]
window.myLine.update()
})
},
},
mounted() {
axios.get('https://api.covid19india.org/data.json').then((response) => {
this.results = response.data.statewise
this.chartsdata = response.data.cases_time_series.reverse()
const startDate = moment()
.subtract(this.displaydays, 'days')
.format('DD MMMM')
const chartDisplay = this.chartsdata
.filter((d, i) => moment(d.date).isSameOrAfter(startDate))
.sort((a, b) => moment(a.date) - moment(b.date))
const dailyConfirmed = chartDisplay.map((d) => d.dailyconfirmed)
const dailyRecovered = chartDisplay.map((d) => d.dailyrecovered)
const labels = chartDisplay.map((d) => d.date)
let config = {
type: 'line',
data: {
labels,
datasets: [
{
label: 'New cases',
backgroundColor: '#E64A35',
borderColor: '#E64A35',
data: dailyConfirmed,
fill: false,
},
{
label: 'New recoveries',
fill: false,
backgroundColor: 'green',
borderColor: 'green',
data: dailyRecovered,
},
],
},
options: {
responsive: true,
title: {
display: true,
text: 'Daily changes',
},
tooltips: {
mode: 'index',
intersect: false,
},
hover: {
mode: 'nearest',
intersect: true,
},
scales: {
xAxes: [
{
display: true,
scaleLabel: {
display: true,
labelString: 'Time',
},
},
],
yAxes: [
{
display: true,
scaleLabel: {
display: true,
labelString: 'Cases',
},
},
],
},
},
}
let ctx = document.getElementById('canvas').getContext('2d')
window.myLine = new Chart(ctx, config)
})
},
})