Files
cssd-back/resources/js/vue/views/Statistics/Chart.vue
T
2019-05-10 19:27:01 +04:30

51 lines
1.1 KiB
Vue

<template>
<div class="small">
<pie-chart :chart-data="datacollection"></pie-chart>
<bar-chart :chart-data="datacollection"></bar-chart>
<button @click="fillData()">Randomize</button>
</div>
</template>
<script>
import BarChart from '@/plugins/chart/BarChart.js'
import PieChart from '@/plugins/chart/PieChart.js'
export default {
components: {
BarChart,
PieChart
},
data () {
return {
datacollection: null
}
},
mounted () {
this.fillData()
},
methods: {
fillData () {
this.datacollection = {
labels: [this.getRandomInt(), this.getRandomInt()],
datasets: [
{
label: 'Data One',
backgroundColor: ['#f87979', '#ccc'],
data: [this.getRandomInt(), this.getRandomInt()]
}
]
}
},
getRandomInt () {
return Math.floor(Math.random() * (50 - 5 + 1)) + 5
}
}
}
</script>
<style>
.small {
max-width: 600px;
margin: 150px auto;
}
</style>