Newer
Older
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- <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">
<a type="button" class="" @click="monthAxisBack"><i class="material-icons">chevron_left</i></a>
<a type="button" class="" @click="fullView"><i class="material-icons">fullscreen</i></a>
<a type="button" class="" @click="currentMonth"><i class="material-icons">today</i></a>
<a type="button" class="" @click="monthAxisForward"><i class="material-icons">chevron_right</i></a>
</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>
<style lang="scss">
@import "../assets/app.scss";
$big_icon : 36px !important;
i {
color: $thddonaublue;
font-size: $big_icon;
};
</style>
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
<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
}
}
}
}
lineChart.options.scales.x.min = dateslength - 30
lineChart.options.scales.x.max = dateslength
console.log('here')
chartRef.value.update(250)
}
if (lineChart.options.scales.x.max <= dateslength - 30) {
lineChart.options.scales.x.min += 30
lineChart.options.scales.x.max += 30
}
chartRef.value.update(250)
}
if (lineChart.options.scales.x.min >= 0) {
lineChart.options.scales.x.min -= 30
lineChart.options.scales.x.max -= 30
}
chartRef.value.update(250)
}
lineChart.options.scales.x.min = 0
lineChart.options.scales.x.max = dateslength
chartRef.value.update(250)
}
return {
lineChart,
CasesHistory,
CoronaStatBY,
monthAxisForward,
monthAxisBack,
fullView
}
},
data () {
// return {
// cases: [Number]
// }
},
methods: {
async getCoronaStat () {
await axios
.get('https://api.corona-zahlen.org/germany')
.then(response => (this.CoronaStatBY = response.data))
}
}
}
</script>