Skip to content

Commit 56666ce

Browse files
committed
update user-payment-statistic
1 parent e517608 commit 56666ce

File tree

9 files changed

+133
-66
lines changed

9 files changed

+133
-66
lines changed

src/app/features/statistics/pages/user-payment-statistic/user-payment-statistic.component.html

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,37 @@ <h1>Thống kê tiền nạp</h1>
3939
</div>
4040

4141
<div class="charts-grid">
42+
<!-- Bar chart cho Nạp & Mua -->
4243
<div class="chart-wrapper">
43-
<app-multi-line-chart
44+
<app-multi-chart
4445
[categories]="chartCategories"
45-
[seriesData]="chartSeries"
46-
></app-multi-line-chart>
46+
[seriesData]="barChartSeries"
47+
[title]="
48+
'Thống kê Nạp & Mua theo ngày trong tháng ' +
49+
selectedMonth +
50+
'/' +
51+
selectedYear
52+
"
53+
[type]="'bar'"
54+
></app-multi-chart>
55+
</div>
56+
57+
<!-- Line chart cho Số dư ví -->
58+
<div class="chart-wrapper">
59+
<app-multi-chart
60+
[categories]="chartCategories"
61+
[seriesData]="lineChartSeries"
62+
[title]="
63+
'Thống kê Số dư ví theo ngày trong tháng ' +
64+
selectedMonth +
65+
'/' +
66+
selectedYear
67+
"
68+
[type]="'line'"
69+
></app-multi-chart>
4770
</div>
4871
</div>
72+
4973
<!-- Bảng chi tiết -->
5074
<div class="table-wrapper">
5175
<app-table

src/app/features/statistics/pages/user-payment-statistic/user-payment-statistic.component.ts

Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,12 @@ import {
1111
} from '../../../../core/models/statistics.model';
1212
import { LineChartComponent } from '../../../../shared/components/my-shared/line-chart/line-chart';
1313
import { TableComponent } from '../../../../shared/components/my-shared/table/table.component';
14-
import { MultiLineChartComponent } from '../../../../shared/components/my-shared/multi-line-chart/multi-line-chart';
14+
import { MultiChartComponent } from '../../../../shared/components/my-shared/multi-chart/multi-chart';
1515

1616
@Component({
1717
selector: 'app-user-payment-statistics',
18-
imports: [CommonModule, FormsModule, MultiLineChartComponent, TableComponent],
18+
standalone: true,
19+
imports: [CommonModule, FormsModule, MultiChartComponent, TableComponent],
1920
templateUrl: './user-payment-statistic.component.html',
2021
styleUrls: ['./user-payment-statistic.component.scss'],
2122
})
@@ -114,7 +115,8 @@ export class UserPaymentStatisticsComponent implements OnInit, OnDestroy {
114115

115116
// chart data
116117
chartCategories: string[] = [];
117-
chartSeries: { name: string; data: number[] }[] = [];
118+
barChartSeries: { name: string; data: number[] }[] = [];
119+
lineChartSeries: { name: string; data: number[] }[] = [];
118120

119121
constructor(private statisticsService: StatisticsService) {}
120122

@@ -141,20 +143,17 @@ export class UserPaymentStatisticsComponent implements OnInit, OnDestroy {
141143

142144
this.calculateTotals(this.paymentData);
143145
// ✅ Gán dữ liệu BE vào chart
144-
const { categories, seriesData } = this.convertToChartData(
145-
this.paymentData
146-
);
146+
const { categories, barSeriesData, lineSeriesData } =
147+
this.convertToChartData(this.paymentData);
147148
this.chartCategories = categories;
148-
this.chartSeries = seriesData;
149+
this.barChartSeries = barSeriesData;
150+
this.lineChartSeries = lineSeriesData;
149151

150152
// ✅ Tính tổng nạp + chi
151153
this.calculateTotals(this.paymentData);
152154

153155
// ✅ Chuẩn bị dữ liệu 2 bảng
154156
this.splitDataForTables(this.paymentData);
155-
console.log('Filtered Data:', this.paymentData);
156-
console.log(this.chartCategories);
157-
console.log(this.chartSeries);
158157
}
159158

160159
loadPayment(): void {
@@ -174,11 +173,11 @@ export class UserPaymentStatisticsComponent implements OnInit, OnDestroy {
174173

175174
this.calculateTotals(this.paymentData);
176175
// ✅ Gán dữ liệu BE vào chart
177-
const { categories, seriesData } = this.convertToChartData(
178-
this.paymentData
179-
);
176+
const { categories, barSeriesData, lineSeriesData } =
177+
this.convertToChartData(this.paymentData);
180178
this.chartCategories = categories;
181-
this.chartSeries = seriesData;
179+
this.barChartSeries = barSeriesData;
180+
this.lineChartSeries = lineSeriesData;
182181

183182
// ✅ Tính tổng nạp + chi
184183
this.calculateTotals(this.paymentData);
@@ -207,31 +206,31 @@ export class UserPaymentStatisticsComponent implements OnInit, OnDestroy {
207206
}
208207

209208
convertToChartData(data: any[]) {
210-
const categories = data.map((item) => {
211-
item.day;
212-
console.log('Item day:', item.day);
213-
return item.day;
214-
});
209+
const categories = data.map((item) => item.day);
215210

216-
const seriesData = [
211+
// Dữ liệu cho Bar chart (Nạp + Mua)
212+
const barSeriesData = [
217213
{
218-
name: 'Deposit',
214+
name: 'Tiền nạp',
219215
data: data.map((item) => item.depositAmount),
220216
},
221217
{
222-
name: 'Purchase',
218+
name: 'Tiền mua',
223219
data: data.map((item) => item.purchaseAmount),
224220
},
221+
];
222+
223+
// Dữ liệu cho Line chart (Wallet)
224+
const lineSeriesData = [
225225
{
226-
name: 'Wallet Balance',
226+
name: 'Số dư ví',
227227
data: data.map((item) => item.walletBalance),
228228
},
229229
];
230230

231-
console.log('categories:', categories);
232-
console.log('seriesData:', seriesData);
233-
return { categories, seriesData };
231+
return { categories, barSeriesData, lineSeriesData };
234232
}
233+
235234
// table
236235
tableDepositHeaders = [
237236
{ label: 'Ngày', value: 'day' },

src/app/features/student-statistic/test-statistic/student-statistic.component.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@
112112
]
113113
}
114114
]"
115-
[height]="350"
116115
[chartTitle]="'Tỷ lệ hoàn thành bài của học sinh trong tổ chức'"
117116
></fx-line-chart>
118117

src/app/shared/components/my-shared/line-chart/line-chart.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
ApexFill,
2020
} from 'ng-apexcharts';
2121

22-
2322
export type ChartOptions = {
2423
series: ApexAxisChartSeries;
2524
chart: ApexChart;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div class="chart-container">
2+
@if (this.title) {
3+
<div class="chart-title">{{ title }}</div>
4+
} @if (chartOptions.series.length && chartOptions.xaxis.categories.length) {
5+
<div class="chart-body">
6+
<apx-chart
7+
[series]="chartOptions.series"
8+
[chart]="chartOptions.chart"
9+
[dataLabels]="chartOptions.dataLabels"
10+
[plotOptions]="chartOptions.plotOptions"
11+
[yaxis]="chartOptions.yaxis"
12+
[legend]="chartOptions.legend"
13+
[fill]="chartOptions.fill"
14+
[stroke]="chartOptions.stroke"
15+
[tooltip]="chartOptions.tooltip"
16+
[xaxis]="chartOptions.xaxis"
17+
></apx-chart>
18+
</div>
19+
} @else {
20+
<div class="chart-error">
21+
Lỗi: Thiếu dữ liệu đầu vào bắt buộc hoặc dữ liệu không hợp lệ để hiển thị
22+
biểu đồ.
23+
</div>
24+
}
25+
</div>
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
.chart-container {
2+
width: 100%;
3+
}
4+
5+
.chart-title {
6+
text-align: center;
7+
font-weight: bold;
8+
margin-bottom: 12px;
9+
}
10+
11+
.chart-body {
12+
width: 100%;
13+
height: 400px; // 👈 đặt chiều cao rõ ràng
14+
}
15+
16+
apx-chart {
17+
display: block;
18+
width: 100% !important;
19+
height: 100% !important;
20+
}

src/app/shared/components/my-shared/multi-line-chart/multi-line-chart.ts renamed to src/app/shared/components/my-shared/multi-chart/multi-chart.ts

Lines changed: 36 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ import {
1717
ApexXAxis,
1818
ApexFill,
1919
ApexTooltip,
20+
ApexTitleSubtitle,
2021
NgApexchartsModule,
2122
} from 'ng-apexcharts';
2223

2324
export type ChartOptions = {
25+
responsive: any;
2426
series: ApexAxisChartSeries;
2527
chart: ApexChart;
2628
dataLabels: ApexDataLabels;
@@ -31,34 +33,40 @@ export type ChartOptions = {
3133
tooltip: ApexTooltip;
3234
stroke: ApexStroke;
3335
legend: ApexLegend;
36+
title: ApexTitleSubtitle;
3437
};
3538

3639
@Component({
37-
selector: 'app-multi-line-chart',
38-
templateUrl: './multi-line-chart.html',
39-
styleUrls: ['./multi-line-chart.scss'],
40+
selector: 'app-multi-chart',
41+
templateUrl: './multi-chart.html',
42+
styleUrls: ['./multi-chart.scss'],
4043
imports: [NgApexchartsModule],
4144
standalone: true,
4245
})
43-
export class MultiLineChartComponent implements OnChanges {
46+
export class MultiChartComponent implements OnChanges {
4447
@ViewChild('chart') chart!: ChartComponent;
4548

46-
// ✅ Nhận categories và series động từ bên ngoài
49+
// ✅ Nhận đầu vào động
4750
@Input() categories: string[] = [];
4851
@Input() seriesData: ApexAxisChartSeries = [];
52+
@Input() title: string = '';
53+
@Input() type: 'bar' | 'line' = 'bar'; // 👈 loại biểu đồ
4954

5055
public chartOptions: ChartOptions = {
5156
series: [],
5257
chart: {
53-
type: 'bar',
54-
height: 350,
58+
type: 'bar', // mặc định
59+
height: '100%', // 👈 thay vì 350 fix cứng
60+
width: '100%', // 👈 ép full width
61+
zoom: {
62+
enabled: false,
63+
},
5564
},
5665
dataLabels: {
5766
enabled: true,
5867
},
5968
stroke: {
60-
curve: 'smooth',
61-
width: 2,
69+
curve: 'smooth', // 👈 chỉ giữ curve
6270
},
6371
xaxis: {
6472
categories: [],
@@ -70,9 +78,7 @@ export class MultiLineChartComponent implements OnChanges {
7078
},
7179
tooltip: {
7280
y: {
73-
formatter: function (val: number) {
74-
return val + ' VND';
75-
},
81+
formatter: (val: number) => val + ' VND',
7682
},
7783
},
7884
legend: {
@@ -82,21 +88,33 @@ export class MultiLineChartComponent implements OnChanges {
8288
opacity: 1,
8389
},
8490
plotOptions: {
85-
bar: {
86-
columnWidth: '55%',
87-
borderRadius: 5,
88-
},
91+
bar: {}, // 👈 để trống, không set width/border
92+
},
93+
title: {
94+
text: '',
95+
align: 'center',
8996
},
97+
responsive: undefined,
9098
};
9199

92100
ngOnChanges(changes: SimpleChanges): void {
93101
this.updateChart();
94102
}
95103

96104
private updateChart() {
105+
// cập nhật loại chart
106+
this.chartOptions.chart.type = this.type;
107+
108+
// nếu là line thì bỏ plotOptions.bar đi
109+
if (this.type === 'line') {
110+
this.chartOptions.plotOptions = {} as ApexPlotOptions;
111+
}
112+
97113
this.chartOptions.series = this.seriesData;
98-
this.chartOptions.xaxis = {
99-
categories: this.categories,
114+
this.chartOptions.xaxis = { categories: this.categories };
115+
this.chartOptions.title = {
116+
text: this.title,
117+
align: 'center',
100118
};
101119
}
102120
}

src/app/shared/components/my-shared/multi-line-chart/multi-line-chart.html

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/app/shared/components/my-shared/multi-line-chart/multi-line-chart.scss

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)