1
0
Fork 0
mirror of https://github.com/Luzifer/mondash.git synced 2024-11-14 02:12:42 +00:00
mondash/src/graph.vue
Knut Ahlers f969a6916d
Apply new linter settings
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2019-08-16 23:33:12 +02:00

56 lines
820 B
Vue

<template>
<div
ref="container"
class="ct-double-octave"
/>
</template>
<script>
import chartist from 'chartist'
import moment from 'moment'
export default {
name: 'Graph',
props: {
metric: {
required: true,
type: Object,
},
},
data() {
return {
chart: null,
}
},
computed: {
data() {
const vh = this.metric.value_history
const labels = []
const series = []
for (const k of Object.keys(vh)) {
labels.push(moment(k * 1000).format('lll'))
series.push(vh[k])
}
return {
labels,
series: [series],
}
},
},
watch: {
metric() {
this.chart.update(this.data)
},
},
mounted() {
this.chart = chartist.Line(this.$refs.container, this.data)
},
}
</script>