Changeset View
Changeset View
Standalone View
Standalone View
src/resources/vue/Admin/Stats.vue
- This file was added.
<template> | |||||
<div id="stats-container" class="container"> | |||||
</div> | |||||
</template> | |||||
<script> | |||||
import { Chart } from 'frappe-charts/dist/frappe-charts.esm.js' | |||||
export default { | |||||
data() { | |||||
return { | |||||
charts: {} | |||||
} | |||||
}, | |||||
mounted() { | |||||
this.loadChart('users') | |||||
}, | |||||
methods: { | |||||
drawChart(name, data) { | |||||
if (!data.title) { | |||||
return | |||||
} | |||||
const ch = new Chart('#chart-' + name, data) | |||||
this.charts[name] = ch | |||||
}, | |||||
loadChart(name) { | |||||
const chart = $('<div>').attr({ id: 'chart-' + name }).appendTo(this.$el) | |||||
this.$root.addLoader(chart) | |||||
axios.get('/api/v4/stats/chart/' + name) | |||||
.then(response => { | |||||
this.$root.removeLoader(chart) | |||||
this.drawChart(name, response.data) | |||||
}) | |||||
} | |||||
} | |||||
} | |||||
</script> |