Feat: Doughnut chart react on datas

This commit is contained in:
Bertrand Benjamin 2018-12-03 11:53:01 +01:00
parent f28d22ecb6
commit c469976d50
5 changed files with 51 additions and 38 deletions

View File

@ -54,13 +54,3 @@ postes:
- SALAISON CHALAM - SALAISON CHALAM
- INTERMARCHE - INTERMARCHE
- LA FERME DU COIN - LA FERME DU COIN
bio:
name: Bio
variant: success
icon: shopping-basket
words:
- BIOCOOP
- LA VIE CLAIRE
- MAISON VITALE

View File

@ -17,6 +17,7 @@
<script> <script>
import { mapGetters } from 'vuex' import { mapGetters } from 'vuex'
import { total } from '../libs/data_processing'
export default { export default {
name: 'box', name: 'box',
props: [ props: [
@ -56,11 +57,7 @@ export default {
} }
}, },
total () { total () {
return Math.round( return total(this.filter_rows())
-this.filter_rows()
.map(x => parseFloat(x.Montant))
.reduce((sum, x) => sum + x, 0)
)
}, },
count () { count () {
} }

View File

@ -1,19 +1,17 @@
<script> <script>
import { Doughnut } from 'vue-chartjs' import { Doughnut, mixins } from 'vue-chartjs'
const { reactiveProp } = mixins
export default { export default {
name: 'pie', name: 'pie',
extends: Doughnut, extends: Doughnut,
props: ['chartdata', 'options'], mixins: [reactiveProp],
props: ['chartData', 'options'],
mounted () { mounted () {
this.renderChart(this.chartdata, this.options) this.renderChart(this.chartData, this.options)
} }
} }
</script> </script>
<style scope> <style scope>
#doughnut-chart {
width: 100px;
height: 100px;
}
</style> </style>

View File

@ -1,11 +1,14 @@
<template> <template>
<div class="container"> <div class="container">
<pie :chartdata="data" :options="options"></pie> <pie :chart-data="chartdata" :options="options" v-if="spendings[0] !== 0"></pie>
</div> </div>
</template> </template>
<script> <script>
import pie from './charjs_donut' import pie from './charjs_donut'
import { mapGetters } from 'vuex'
import { total } from '../libs/data_processing'
export default { export default {
name: 'postesComparison', name: 'postesComparison',
@ -14,27 +17,47 @@ export default {
}, },
data () { data () {
return { return {
data: { selected_tags: [
labels: ["Africa", "Asia", "Europe", "Latin America", "North America"], 'virements',
datasets: [ 'cash',
{ 'autoroute',
label: "Population (millions)", 'essence',
backgroundColor: ["#3e95cd", "#8e5ea2","#3cba9f","#e8c3b9","#c45850"], 'courses',
data: [2478,5267,734,784,433] 'sans tags'
} ],
]
},
options: { options: {
responsive: true, responsive: true,
maintainAspectRatio: false, maintainAspectRatio: false
title: {
display: true,
text: 'Predicted world population (millions) in 2050'
}
} }
} }
}, },
computed: { computed: {
...mapGetters('datas', [
'tag_filter_rows'
]),
chartdata () {
return {
labels: this.selected_tags,
datasets: [
{
label: "Dépenses",
data: this.spendings
}
]
}
},
spendings () {
var tagsSpendings = this.selected_tags.map(tag => {
if (tag) {
return total(this.tag_filter_rows([tag]))
} else {
return 0
}
})
tagsSpendings[tagsSpendings.length - 1] = total(this.tag_filter_rows([])) - tagsSpendings.reduce((sum, a) => sum + a, 0)
console.log(tagsSpendings)
return tagsSpendings
}
}, },
methods: { methods: {
} }

View File

@ -25,3 +25,8 @@ function strContains (string, words, invert) {
} }
} }
export function total (row, field='Montant') {
var sum = row.map(x => parseFloat(x[field]))
.reduce((sum, x) => sum + x, 0)
return Math.round(sum)
}