ver 2
This commit is contained in:
@@ -17,12 +17,43 @@ ChartJS.register(ChartDataLabels);
|
||||
|
||||
const loading = ref(false);
|
||||
const categoriesSums = ref([])
|
||||
const dataTableCategories = ref([])
|
||||
|
||||
|
||||
const fetchCategoriesSums = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
categoriesSums.value = await getTransactionCategoriesSums()
|
||||
// console.log(categoriesSums.value)
|
||||
for (let category of categoriesSums.value) {
|
||||
// console.log(category)
|
||||
// [{
|
||||
// "category": category[0],
|
||||
// "category"+[category[1]]: category[2]
|
||||
// }]
|
||||
// console.log('test')
|
||||
// console.log('dataTableCategories '+ dataTableCategories.value)
|
||||
let categoryInList = dataTableCategories.value.find((listCategory: Category) => {
|
||||
// console.log(listCategory['category'].id)
|
||||
// console.log(category[0].id)
|
||||
return listCategory['category'].id === category[0].id
|
||||
})
|
||||
console.log('cat in list ' + categoryInList)
|
||||
if (categoryInList) {
|
||||
console.log('cat[1] '+ category[1])
|
||||
console.log('cat[2] '+ category[2])
|
||||
categoryInList[category[1]] = category[2]
|
||||
// console.log(categoryInList)
|
||||
} else {
|
||||
dataTableCategories.value.push({'category': category[0]})
|
||||
dataTableCategories.value.filter((listCategory: Category) => {
|
||||
return listCategory['category'].id === category.id
|
||||
})[category[1]] = category[2]
|
||||
}
|
||||
// console.log(categoryInList)
|
||||
}
|
||||
// console.log(dataTableCategories.value)
|
||||
// console.log(categoriesSums.value)
|
||||
} catch (error) {
|
||||
console.error('Error fetching categories sums:', error);
|
||||
}
|
||||
@@ -37,8 +68,8 @@ const fetchCategories = async () => {
|
||||
try {
|
||||
const response = await getCategories('EXPENSE');
|
||||
categories.value = response.data
|
||||
console.log(categories.value.filter(i => i.id==30))
|
||||
selectedCategories.value.push(categories.value.filter(i => i.id==30)[0])
|
||||
console.log(categories.value.filter(i => i.id == 30))
|
||||
selectedCategories.value.push(categories.value.filter(i => i.id == 30)[0])
|
||||
} catch (error) {
|
||||
console.error('Error fetching categories:', error);
|
||||
}
|
||||
@@ -170,9 +201,9 @@ const setChartOptions = () => {
|
||||
offset: 8, // Отступ от точки
|
||||
labels: {
|
||||
|
||||
font: {
|
||||
weight: 'bold'
|
||||
}
|
||||
font: {
|
||||
weight: 'bold'
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -213,8 +244,13 @@ onMounted(async () => {
|
||||
placeholder="Выберите категории"
|
||||
:maxSelectedLabels="3" class="w-full md:w-80"/>
|
||||
|
||||
<Chart v-if="selectedCategories.length > 0" type="line" :data="chartData" :options="chartOptions" class="h-[30rem]"/>
|
||||
<Chart v-if="selectedCategories.length > 0" type="line" :data="chartData" :options="chartOptions"
|
||||
class="h-[30rem]"/>
|
||||
|
||||
{{dataTableCategories}}
|
||||
<DataTable :value="dataTableCategories">
|
||||
<!-- <Column v-for="dataTableCategories"/>-->
|
||||
</DataTable>
|
||||
<!-- {{categories}}-->
|
||||
<!-- {{// chartData}}-->
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user