diff --git a/components/statistics/monthly-chart.tsx b/components/statistics/monthly-chart.tsx
index 56a86d9..140e5fc 100644
--- a/components/statistics/monthly-chart.tsx
+++ b/components/statistics/monthly-chart.tsx
@@ -44,20 +44,35 @@ export function MonthlyChart({
}: MonthlyChartProps) {
const [isExpanded, setIsExpanded] = useState(defaultExpanded);
+ // Calculer l'intervalle dynamiquement selon le nombre de données
+ const getXAxisInterval = () => {
+ if (data.length <= 6) return 0; // Afficher tous les labels pour 6 mois ou moins
+ if (data.length <= 12) return 1; // Afficher un label sur deux pour 7-12 mois
+ return Math.floor(data.length / 12); // Pour plus de 12 mois, afficher environ 12 labels
+ };
+
+ // Formater les labels de manière plus compacte
+ const formatMonthLabel = (month: string) => {
+ // Format: "janv. 24" -> "janv 24" (enlever le point)
+ return month.replace('.', '');
+ };
+
const chartContent = (
<>
{data.length > 0 ? (
-
+ 6 ? 80 : 60 }}>
6 ? -45 : 0}
+ textAnchor={data.length > 6 ? "end" : "middle"}
+ height={data.length > 6 ? 80 : 60}
+ interval={getXAxisInterval()}
+ tickFormatter={formatMonthLabel}
+ tick={{ fontSize: 11 }}
/>
a[0].localeCompare(b[0]))
- .map(([month, values]) => ({
- month: new Date(month + "-01").toLocaleDateString("fr-FR", {
+ // Format months with year: use short format for better readability
+ const sortedMonths = Array.from(monthlyMap.entries()).sort((a, b) =>
+ a[0].localeCompare(b[0])
+ );
+
+ const monthlyChartData: MonthlyChartData[] = sortedMonths.map(
+ ([monthKey, values]) => {
+ const date = new Date(monthKey + "-01");
+
+ // Format: "janv. 24" instead of "janv. 2024" for compactness
+ const monthLabel = date.toLocaleDateString("fr-FR", {
month: "short",
- year: "numeric",
- }),
- revenus: values.income,
- depenses: values.expenses,
- solde: values.income - values.expenses,
- }));
+ });
+ const yearShort = date.getFullYear().toString().slice(-2);
+
+ return {
+ month: `${monthLabel} ${yearShort}`,
+ revenus: values.income,
+ depenses: values.expenses,
+ solde: values.income - values.expenses,
+ };
+ }
+ );
return monthlyChartData;
}, [transactionsData]);