1
I defined an initial value for each information in the graph, in case A,B and C, wanted to know how to add with a value that will be placed in the input.
Project code:
<div class="main">
<chartjs-doughnut v-bind:labels="labels" v-bind:datasets="datasets" v-bind:option="option">
</chartjs-doughnut>
<input type="text" id="number1">
<button @click="soma1()">Colocar</button>
<input type="text" id="number2">
<button @click="soma2()">Colocar</button>
<input type="text" id="number3">
<button @click="soma3()">Colocar</button>
</div>
</template>
<script>
import Motorista from '../services/motoristas'
import axios from 'axios'
var A = 5;
var B = 5;
var C = 5;
// function soma1() {
// let number1 = document.getElementById("number1").value;
// let result = number1 + A.value;
// this.A = result;
// }
console.log(A)
export default {
data() {
return {
motoristas: [],
labels: ["C", "D", "E"],
datasets: [
{
data: [A, B, C],
backgroundColor: ["Red","Yellow","Purple"]
}
],
option: {
title: {
display: true,
position: 'bottom',
text: 'Carteira'
}
}
}
},
mounted() {
this.listar()
this.soma1()
},
methods: {
listar(){
Motorista.listar().then(resposta => {
console.log(resposta.data)
this.motoristas = resposta.data
this.categoriaC = this.motoristas.filter(m => m.categoria == 3).length;
this.categoriaD = this.motoristas.filter(m => m.categoria == 4).length;
this.categoriaE = this.motoristas.filter(m => m.categoria == 5).length;
})
},
soma1(){
let number1 = document.getElementById("number1").value;
let result = number1 + A.value;
this.A = result;
}
},
}
</script>
<style scoped>
</style>
Please, when you explain, always use the whole code because I’m starting in Vue.