[admin] better profilesByLocale chart

This commit is contained in:
Andrea 2022-01-03 17:45:18 +01:00
parent 869b2f848b
commit f5658e7b78
2 changed files with 20 additions and 3 deletions

View File

@ -11,13 +11,20 @@
data: { required: true }, data: { required: true },
cumulative: { type: Boolean }, cumulative: { type: Boolean },
type: {'default': 'line'}, type: {'default': 'line'},
options: {'default': () => { return {
responsive: true,
interaction: {
intersect: false,
mode: 'index',
},
}; }},
}, },
async created() { async created() {
}, },
async mounted() { async mounted() {
if (!process.client) { return; } if (!process.client) { return; }
await this.$loadScript('charts', 'https://cdn.jsdelivr.net/npm/chart.js@2.9.3/dist/Chart.bundle.min.js'); await this.$loadScript('charts', 'https://cdnjs.cloudflare.com/ajax/libs/Chart.js/3.7.0/chart.min.js');
this.drawChart(); this.drawChart();
}, },
methods: { methods: {
@ -35,11 +42,14 @@
labels: Object.keys(this.data), labels: Object.keys(this.data),
datasets: [{ datasets: [{
label: this.label, label: this.label,
data: this.cumulative ? this.accumulate(Object.values(this.data)) : Object.values(this.data), data: this.cumulative
? this.accumulate(Object.values(this.data))
: Object.values(this.data),
fill: false, fill: false,
borderColor: '#C71585', borderColor: '#C71585',
}], }],
}, },
options: this.options,
}); });
}, },
accumulate(values) { accumulate(values) {

View File

@ -94,7 +94,14 @@
<ChartSet name="users" :data="stats.users.chart" init="cumulative"/> <ChartSet name="users" :data="stats.users.chart" init="cumulative"/>
<Chart label="number of profiles by locale" :data="profilesByLocale" type="bar"/> <Chart label="number of profiles by locale" :data="profilesByLocale" type="bar" :options="{
indexAxis: 'y',
responsive: true,
interaction: {
intersect: false,
mode: 'y',
},
}"/>
<section> <section>
<Icon v="id-card"/> <Icon v="id-card"/>