"use client"; import { CartesianGrid, Line, LineChart, XAxis, YAxis } from "recharts"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { type ChartConfig, ChartContainer, ChartLegend, ChartLegendContent, ChartTooltip, ChartTooltipContent, } from "@/components/ui/chart"; import { cn } from "@/lib/utils"; interface ChartGroup5Props { className?: string; } const monthLabel = (monthIndex: number) => new Intl.DateTimeFormat("fa-IR", { month: "short" }).format( new Date(2025, monthIndex, 1), ); const currencyFormatter = new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", minimumFractionDigits: 0, maximumFractionDigits: 0, }); const compactCurrencyFormatter = new Intl.NumberFormat("fa-IR", { style: "currency", currency: "IRR", notation: "compact", minimumFractionDigits: 0, maximumFractionDigits: 1, }); const percentChangeFormatter = new Intl.NumberFormat("fa-IR", { maximumFractionDigits: 1, minimumFractionDigits: 1, signDisplay: "exceptZero", }); const currentData = [ { month: monthLabel(0), value: 18600 }, { month: monthLabel(1), value: 30500 }, { month: monthLabel(2), value: 23700 }, { month: monthLabel(3), value: 27300 }, { month: monthLabel(4), value: 20900 }, { month: monthLabel(5), value: 31400 }, ]; const previoIRRata = [ { month: monthLabel(0), value: 15200 }, { month: monthLabel(1), value: 24800 }, { month: monthLabel(2), value: 21100 }, { month: monthLabel(3), value: 22500 }, { month: monthLabel(4), value: 19400 }, { month: monthLabel(5), value: 26200 }, ]; const combinedData = currentData.map((item, index) => ({ month: item.month, current: item.value, previous: previoIRRata[index].value, })); const chartConfig = { current: { label: "امسال", color: "var(--chart-1)" }, previous: { label: "سال قبل", color: "var(--chart-4)" }, } satisfies ChartConfig; const ChartGroup5 = ({ className }: ChartGroup5Props) => { const currentTotal = currentData.reduce((sum, item) => sum + item.value, 0); const previousTotal = previoIRRata.reduce((sum, item) => sum + item.value, 0); const difference = currentTotal - previousTotal; const growthPercent = ((currentTotal - previousTotal) / previousTotal) * 100; return (
مقایسه سال به سال عملکرد درآمد در برابر سال قبل compactCurrencyFormatter.format(Number(v)) } /> currencyFormatter.format(Number(value)) } /> } cursor={{ stroke: "var(--border)", strokeDasharray: "4 4" }} /> } /> خلاصه مقایسه دوره‌ای
امسال {currencyFormatter.format(currentTotal)}
سال قبل {currencyFormatter.format(previousTotal)}
تفاوت +{currencyFormatter.format(difference)}
رشد {percentChangeFormatter.format(growthPercent)}٪
میانگین ماهانه (امسال) {currencyFormatter.format(Math.round(currentTotal / 6))}
میانگین ماهانه (سال قبل) {currencyFormatter.format(Math.round(previousTotal / 6))}
); }; export { ChartGroup5 };