79 lines
2.0 KiB
Vue
79 lines
2.0 KiB
Vue
<template>
|
|
<div class="p-2 border border-gray-500 mt-4">
|
|
<label class="block mb-2 font-bold">Comportamiento diario</label>
|
|
|
|
<client-only>
|
|
<LineChart :data="chartData" />
|
|
</client-only>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
props: {
|
|
data: { type: Array, required: true, default: () => [] },
|
|
labels: { type: Array, required: true, default: () => [] },
|
|
},
|
|
methods: {
|
|
randomRgba() {
|
|
let o = Math.round,
|
|
r = Math.random,
|
|
s = 255
|
|
|
|
return `rgba(${o(r() * s)}, ${o(r() * s)}, ${o(r() * s)}, 1)`
|
|
},
|
|
},
|
|
computed: {
|
|
chartData() {
|
|
const datasets = []
|
|
const final = []
|
|
|
|
for (let i = 0; i < this.data.length; i++) {
|
|
const data = []
|
|
|
|
for (let j = 0; j < this.data[i].dias.length; j++) {
|
|
data.push(this.data[i].dias[j].prestamos.length)
|
|
if (this.data.length > 1) {
|
|
if (i === 0) final.push(0)
|
|
final[j] += this.data[i].dias[j].prestamos.length
|
|
}
|
|
}
|
|
datasets.push({
|
|
label: this.data[i].institucion,
|
|
data,
|
|
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
borderColor: this.randomRgba(),
|
|
borderWidth: 2,
|
|
})
|
|
}
|
|
if (this.data.length === 1)
|
|
for (let i = 0; i < this.data[0].modulos.length; i++) {
|
|
const data = []
|
|
|
|
for (let j = 0; j < this.data[0].modulos[i].dias.length; j++)
|
|
data.push(this.data[0].modulos[i].dias[j].prestamos.length)
|
|
datasets.push({
|
|
label: this.data[0].modulos[i].modulo,
|
|
data,
|
|
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
borderColor: this.randomRgba(),
|
|
borderWidth: 2,
|
|
})
|
|
}
|
|
if (this.data.length > 1)
|
|
datasets.push({
|
|
label: 'Total',
|
|
data: final,
|
|
backgroundColor: 'rgba(0, 0, 0, 0)',
|
|
borderColor: this.randomRgba(),
|
|
borderWidth: 2,
|
|
})
|
|
return {
|
|
labels: this.labels,
|
|
datasets,
|
|
}
|
|
},
|
|
},
|
|
}
|
|
</script>
|