Newer
Older
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<template>
<!-- <div v-for="CityHistory in CasesHistory.data['09271'].history" :key="CityHistory.date" class="weather-data">
<div class="cases">
<div>
<span>{{CityHistory.date}}</span>
</div>
<div>
<span class="location">{{CityHistory.cases}}</span>
</div>
</div>
</div> -->
<div class="container h-">
<!-- <button v-on:click="getlCases(CasesHistory.data['09271'].history)">Get Corona Data</button> -->
<h5 class="h3 mb-0">Line chart</h5>
<div class="card">
<!-- Card header -->
<div class="d-flex justify-content-around p-3">
<button type="button" class="btn btn-outline-secondary" @click="add4">2 Monaten weiter </button>
<button type="button" class="btn btn-outline-secondary" @click="minus4">2 Monten züruck</button>
<button type="button" class="btn btn-outline-secondary" @click="showLastMonth">Letzte Montat</button>
<button type="button" class="btn btn-outline-secondary" @click="fullview">Voller Ansicht</button>
</div>
<!-- Card body -->
<div class="card-body ">
<div class="chart">
<vue3-chart-js
:id="lineChart.id"
:type="lineChart.type"
ref="chartRef"
:data="lineChart.data"
:options="lineChart.options"
/>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import axios from 'axios'
import Vue3ChartJs from '@j-t-mcc/vue3-chartjs'
import zoomPlugin from 'chartjs-plugin-zoom'
import dataLabels from 'chartjs-plugin-datalabels'
import { onBeforeMount, ref } from 'vue'
// globally registered and available for all charts
Vue3ChartJs.registerGlobalPlugins([zoomPlugin])
export default {
name: 'App',
components: {
Vue3ChartJs
},
setup () {
const chartRef = ref(null) // ref(0)
const cases = []
const dates = []
let dateslength = 0
const CasesHistory = ref({
data: {
'09271': {
history: []
}
}
})
var CoronaStatBY = {
data: {}
}
// const cases = async () => {
// return await getlCases(CasesHistory.value.data['09271'].history)
// }
async function getCoronaStat () {
await axios
.get('https://api.corona-zahlen.org/districts/09271/history/cases')
.then(response => (CasesHistory.value = response.data))
}
onBeforeMount(async () => {
await getCoronaStat()
const his = CasesHistory.value.data['09271'].history
his.forEach(element => {
// lineChart.data.labels.push(element.date.substr(0, 10))
// lineChart.data.datasets[0].data.push(element.cases)
cases.push(element.cases)
dates.push(element.date.substr(0, 10))
})
dateslength = cases.length
chartRef.value.update(1)
})
const lineChart = {
id: 'line',
type: 'bar',
// locally registered and available for this chart
plugins: [dataLabels],
data: {
labels: dates,
datasets: [
{
label: 'Neubefall',
data: cases,
borderColor: 'black',
backgroundColor: ['#bdc3c7']
}
]
},
options: {
responsive: true,
plugins: {
zoom: {
zoom: {
wheel: {
enabled: true
},
pinch: {
enabled: true
},
mode: 'x'
},
pan: {
enabled: true,
mode: 'xy'
}
},
datalabels: {
backgroundColor: function (context) {
return context.dataset.backgroundColor
},
borderRadius: 4,
color: 'white',
font: {
weight: 'bold'
},
formatter: Math.round,
padding: 6
}
},
scales: {
x: {
min: 0,
max: 500
}
}
}
}
const showLastMonth = () => {
lineChart.options.scales.x.min = dateslength - 30
lineChart.options.scales.x.max = dateslength
console.log('here')
chartRef.value.update(250)
}
const add4 = () => {
if (lineChart.options.scales.x.max <= dateslength - 30) {
lineChart.options.scales.x.min += 30
lineChart.options.scales.x.max += 30
}
chartRef.value.update(250)
}
const minus4 = () => {
if (lineChart.options.scales.x.min >= 0) {
lineChart.options.scales.x.min -= 30
lineChart.options.scales.x.max -= 30
}
chartRef.value.update(250)
}
const fullview = () => {
lineChart.options.scales.x.min = 0
lineChart.options.scales.x.max = dateslength
chartRef.value.update(250)
}
return {
lineChart,
CasesHistory,
CoronaStatBY,
showLastMonth,
chartRef,
add4,
minus4,
fullview
}
},
data () {
// return {
// cases: [Number]
// }
},
methods: {
async getCoronaStat () {
await axios
.get('https://api.corona-zahlen.org/germany')
.then(response => (this.CoronaStatBY = response.data))
}
}
}
</script>