график
This commit is contained in:
1 parent
2ad0211d5f
commit
5f47f0682b
5 files changed
+142
-53
No files matched your search
@@ -1,20 +1,47 @@
|
||||
<template>
|
||||
|
||||
<v-card class="h-100 ">
|
||||
<line-graph v-if="data!==null" :data="data" :options="options"/>
|
||||
|
||||
<!-- <line-graph v-if="data!==null" :data="data" ref ='linear' :options="options"/> -->
|
||||
<Line v-if="data!==null" :data="data" ref ='linear' :options="options" />
|
||||
</v-card>
|
||||
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import lineGraph from '@/components/graph/line-graph.vue'
|
||||
// import lineGraph from '@/components/graph/line-graph.vue'
|
||||
import moment from 'moment'
|
||||
import {computed, onMounted, ref, watch } from 'vue'
|
||||
import { usePortalFilterStore } from '@/store/AboutPortalFilter'
|
||||
import {formatComa, splitname} from '@/utils/universal_functions'
|
||||
import {
|
||||
Chart as ChartJS,
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
LineElement,
|
||||
Title,
|
||||
Tooltip,
|
||||
Legend,
|
||||
TimeScale
|
||||
} from 'chart.js'
|
||||
import { Line } from 'vue-chartjs'
|
||||
|
||||
import ChartDataLabels from 'chartjs-plugin-datalabels'
|
||||
import 'chartjs-adapter-moment'
|
||||
ChartJS.register(
|
||||
ChartDataLabels,
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
LineElement,
|
||||
Title,
|
||||
Tooltip,
|
||||
Legend,
|
||||
TimeScale
|
||||
)
|
||||
export default {
|
||||
components: {
|
||||
lineGraph,
|
||||
Line,
|
||||
},
|
||||
|
||||
props: {
|
||||
@@ -23,10 +50,16 @@ export default {
|
||||
default: () => {}
|
||||
},
|
||||
|
||||
period: {
|
||||
type: Object,
|
||||
default: () => {}
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
setup(props, {emit}) {
|
||||
|
||||
const filterStore = usePortalFilterStore()
|
||||
const between = ref(0)
|
||||
const arrlines = {
|
||||
// labels: [''],
|
||||
datasets: [
|
||||
@@ -57,35 +90,38 @@ export default {
|
||||
yAxisID: 'y'
|
||||
}
|
||||
,
|
||||
// {
|
||||
// label: 'CRR',
|
||||
// backgroundColor: '#673AB7',
|
||||
// borderColor: '#673AB7',
|
||||
// borderWidth: 3,
|
||||
// cubicInterpolationMode: 'monotone',
|
||||
// data: [],
|
||||
// func: (val)=>{return val},
|
||||
// hidden: true,
|
||||
// datakey: "crr",
|
||||
// customlabel: [],
|
||||
// tooltips: true,
|
||||
{
|
||||
label: 'CRR',
|
||||
backgroundColor: '#673AB7',
|
||||
borderColor: '#673AB7',
|
||||
borderWidth: 3,
|
||||
cubicInterpolationMode: 'monotone',
|
||||
data: [],
|
||||
func: (val, key)=>{ return crrfunc(key)
|
||||
},
|
||||
hidden: true,
|
||||
datakey: "crr",
|
||||
customlabel: [],
|
||||
tooltips: true,
|
||||
yAxisID: 'y1'
|
||||
|
||||
// }
|
||||
// ,
|
||||
// {
|
||||
// label: 'BR',
|
||||
// backgroundColor: '#283593',
|
||||
// borderColor: '#283593',
|
||||
// borderWidth: 3,
|
||||
// cubicInterpolationMode: 'monotone',
|
||||
// data: [],
|
||||
// func: (val)=>{return val},
|
||||
// datakey: "br",
|
||||
// hidden: true,
|
||||
// customlabel: [],
|
||||
// tooltips: true
|
||||
// }
|
||||
// ,
|
||||
}
|
||||
,
|
||||
{
|
||||
label: 'BR',
|
||||
backgroundColor: '#283593',
|
||||
borderColor: '#283593',
|
||||
borderWidth: 3,
|
||||
cubicInterpolationMode: 'monotone',
|
||||
data: [],
|
||||
func: (val)=>{return parseFloat((val.br/val.unic.length*100).toFixed(2))},
|
||||
datakey: "br",
|
||||
hidden: true,
|
||||
customlabel: [],
|
||||
tooltips: true,
|
||||
yAxisID: 'y1'
|
||||
}
|
||||
,
|
||||
{
|
||||
label: 'PPV',
|
||||
backgroundColor: '#EF9A9A',
|
||||
@@ -102,36 +138,81 @@ export default {
|
||||
}
|
||||
]
|
||||
}
|
||||
const datachanged=()=> {
|
||||
const dataf=computed({get() {
|
||||
fullpercreate()
|
||||
let data1 = moment(filterStore.date_period.enddate)
|
||||
let data2 = moment(filterStore.date_period.startdate)
|
||||
between.value = data1.diff(data2, 'days') + 1
|
||||
let res = null
|
||||
console.log("sdssdss");
|
||||
if (Object.keys(props.dataLineChart).length>0){
|
||||
res = arrlines
|
||||
res.labels=[]
|
||||
console.log(props.dataLineChart, 'uuuuuuuuuuuuuuuuuuuuuu');
|
||||
// console.log(props.dataLineChart, 'uuuuuuuuuuuuuuuuuuuuuu');
|
||||
for(let [key,val] of Object.entries(props.dataLineChart))
|
||||
|
||||
{
|
||||
res.datasets.forEach((e) => {
|
||||
e.data.push(e.func(val))
|
||||
e.data.push(e.func(val,key))
|
||||
|
||||
// e.data = [10,20,30]
|
||||
});
|
||||
|
||||
res.labels.push(formatComa(key))
|
||||
}
|
||||
console.log(res, "kdjshskjhd");
|
||||
|
||||
// console.log(fullper.value,"reeeeeeee"); // console.log(res, "kdjshskjhd");
|
||||
}
|
||||
// res.datasets[1].data=[]
|
||||
// console.log(res,"reeeeeeee");
|
||||
|
||||
return res
|
||||
}
|
||||
watch(()=>props.dataLineChart,()=>{
|
||||
console.log('changed');
|
||||
data.value = datachanged()
|
||||
},{deep:true})
|
||||
|
||||
const data = ref(datachanged())
|
||||
}})
|
||||
|
||||
const fullper = ref([])
|
||||
const fullpercreate = () => {
|
||||
console.log(props.period, 'ddddddddddddd');
|
||||
let arr = []
|
||||
props.period.period.forEach((e) => {
|
||||
let ind = arr.findIndex(el => el.visitdate == e.visitdate)
|
||||
|
||||
if (ind ==-1) {
|
||||
arr.push({visitdate: e.visitdate, user: Array.from(new Set([e.user.id]))})
|
||||
}
|
||||
else {
|
||||
arr[ind].user = Array.from(new Set(arr[ind].user).add(e.user.id))
|
||||
}
|
||||
})
|
||||
fullper.value= [...props.period.before, ...arr]
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// const data = ref(datachanged.value)
|
||||
const crrfunc = (date)=>{
|
||||
// let h = new Date('2024-01-20') >=moment(new Date(date)).subtract(between.value*2, 'd')
|
||||
let baseunic = unicperson(fullper.value.filter(e => new Date(e.visitdate) >=moment(new Date(date)).subtract(between.value*2, 'd') && new Date(e.visitdate) < moment(new Date(date)).subtract(between.value, 'd')))
|
||||
let crrunic = unicperson(fullper.value.filter(e => new Date(e.visitdate) >=moment(new Date(date)).subtract(between.value, 'd') && new Date(e.visitdate) < new Date(date)))
|
||||
let bothuser = new Set([...baseunic].filter(element => crrunic.has(element)))
|
||||
// console.log(h);
|
||||
console.log(baseunic, crrunic, bothuser, "date");
|
||||
return parseFloat((bothuser.size*100/baseunic.size).toFixed(2))
|
||||
}
|
||||
|
||||
const unicperson = (arr) => {
|
||||
|
||||
let arrnew =[]
|
||||
arr.forEach(e => arrnew.push(...e.user) )
|
||||
return new Set(arrnew)
|
||||
}
|
||||
|
||||
const data=computed({get() {return JSON.parse(JSON.stringify(dataf.value))
|
||||
}
|
||||
})
|
||||
|
||||
const options = {
|
||||
plugins: {
|
||||
@@ -207,10 +288,18 @@ export default {
|
||||
|
||||
// // console.log(props.dataLineChart,'dataYear2 -------------');
|
||||
// }
|
||||
|
||||
// const linear=ref(null)
|
||||
// watch(()=>props.dataLineChart,(newValue, oldValue)=>{
|
||||
// if (linear.value!==null) {
|
||||
// renderChart(data.value, options)
|
||||
// }
|
||||
// linear.value.chart.datasets =data.value.datasets
|
||||
|
||||
// },{deep:true})
|
||||
return {
|
||||
data,
|
||||
options,
|
||||
// linear
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@ export default {
|
||||
}
|
||||
|
||||
const arrforline=() => {
|
||||
|
||||
console.log(props.dataLineChart, 'props.dataLineChart');
|
||||
Object.entries(props.dataLineChart).forEach(e => {
|
||||
const [key, value] = e
|
||||
arrlines.value.datasets[0].data.push(value.count)
|
||||
@@ -127,7 +127,7 @@ export default {
|
||||
|
||||
|
||||
|
||||
console.log( data1.diff(data2, 'days'), 'props.alldata')
|
||||
console.log(between, 'props.alldata')
|
||||
return res
|
||||
}
|
||||
})
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
</v-col>
|
||||
<v-col lg=9>
|
||||
|
||||
<line-chart :dataLineChart="dataLineChart" />
|
||||
<line-chart :dataLineChart="dataLineChart" :period="{before:alldata.beforperiod,period:alldata.period}"/>
|
||||
</v-col>
|
||||
<v-col >
|
||||
<v-btn block class="text-caption" @click="filter='year'">Год</v-btn>
|
||||
@@ -35,6 +35,7 @@
|
||||
<v-row no-gutters class="h-100 gap">
|
||||
<v-col class="flex-column d-flex">
|
||||
<v-row no-gutters class="flex-column gap" >
|
||||
<my-helper :pretext="alldata.beforperiod"/>
|
||||
<my-helper :pretext="alldata.period"/>
|
||||
<v-col v-for="x in cardtotal" :key=x>
|
||||
<card-total :indicator=x />
|
||||
|
||||
Reference in new issue
Block a user