Files
PORTAL_COD2/src/front/src/components/UI/aboutportal/line-chart.vue
T

148 lines
4.0 KiB
Vue

<template>
<v-card class="h-100">
<line-graph :data="data" :options="options"/>
</v-card>
</template>
<script>
import lineGraph from '@/components/graph/line-graph.vue'
import {computed } from 'vue'
import {formatComa, splitname} from '@/utils/universal_functions'
export default {
components: {
lineGraph,
},
props: {
dataLineChart: {
type: Object,
default: () => {}
}
},
setup(props, {emit}) {
const arrlines = {}
const data = computed({
get() {
arrlines.value = {
labels: [],
datasets: [
{
label: 'Открыто страниц',
backgroundColor: 'crimson',
borderColor: 'crimson',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
hidden: true,
tooltips: false
},
{
label: 'Активные пользователи',
backgroundColor: 'teal',
borderColor: 'teal',
borderWidth: 3,
cubicInterpolationMode: 'monotone',
data: [],
customlabel: [],
tooltips: true
}
]
}
arrforline()
return arrlines.value
}
})
const options = {
plugins: {
datalabels: {
color: 'grey',
align: 'top',
display: 'auto'
},
legend: {
labels: {
color: 'grey',
}
},
tooltip: {
displayColors: false,
callbacks: {
label: function(context) {
let label = context.dataset.label || '';
if (context.datasetIndex==1) {
if (context.parsed.y !== null) {
label =arrlines.value.datasets[1].customlabel[context.dataIndex];
}
return label
}
}
}
}
},
scales: {
x: {
grid: {
color: 'white',
}
},
y: {
ticks: {
stepSize: 10
},
offset: true,
grid: {
color: 'white',
}
}
},
responsive: true,
maintainAspectRatio: false
}
const arrforline=() => {
// let datas =
// props.visiting.reduce((acc, item) => {
// if (!acc[item.visitdate]) {
// acc[item.visitdate] = {unic: [], count: 0}
// }
// acc[item.visitdate]['count'] += item.count
// if (!acc[item.visitdate]['unic'].includes(splitname(item.author)))
// {
// acc[item.visitdate]['unic'].push(splitname(item.author))
// }
// return acc
// }, {})
Object.entries(props.dataLineChart).forEach(e => {
const [key, value] = e
arrlines.value.datasets[0].data.push(value.count)
arrlines.value.datasets[1].data.push(value.unic.length)
arrlines.value.labels.push(formatComa(key))
arrlines.value.datasets[1].customlabel.push(props.dataLineChart[key].unic)
})
}
return {
data,
options,
}
}
}
</script>
<style>
canvas {
flex: 1!important
}
</style>