124 lines
3.0 KiB
TypeScript
124 lines
3.0 KiB
TypeScript
"use client";
|
|
|
|
import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts";
|
|
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle,
|
|
} from "@/components/ui/card";
|
|
import {
|
|
type ChartConfig,
|
|
ChartContainer,
|
|
ChartTooltip,
|
|
ChartTooltipContent,
|
|
} from "@/components/ui/chart";
|
|
import { cn } from "@/lib/utils";
|
|
|
|
interface ChartCard3Props {
|
|
title?: string;
|
|
description?: string;
|
|
className?: string;
|
|
}
|
|
|
|
const monthLabel = (monthIndex: number) =>
|
|
new Intl.DateTimeFormat("fa-IR", { month: "short" }).format(
|
|
new Date(2025, monthIndex, 1),
|
|
);
|
|
|
|
const chartData = [
|
|
{ month: monthLabel(0), value: 186 },
|
|
{ month: monthLabel(1), value: 305 },
|
|
{ month: monthLabel(2), value: 237 },
|
|
{ month: monthLabel(3), value: 273 },
|
|
{ month: monthLabel(4), value: 209 },
|
|
{ month: monthLabel(5), value: 214 },
|
|
];
|
|
|
|
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: 0,
|
|
});
|
|
|
|
const chartConfig = {
|
|
value: {
|
|
label: "فروش",
|
|
color: "var(--chart-1)",
|
|
},
|
|
} satisfies ChartConfig;
|
|
|
|
const ChartCard3 = ({
|
|
title = "فروش ماهانه",
|
|
description = "عملکرد فروش به تفکیک ماه",
|
|
className,
|
|
}: ChartCard3Props) => {
|
|
return (
|
|
<Card
|
|
dir="rtl"
|
|
lang="fa"
|
|
className={cn("w-full max-w-2xl text-start", className)}
|
|
>
|
|
<CardHeader>
|
|
<CardTitle>{title}</CardTitle>
|
|
<CardDescription>{description}</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<ChartContainer config={chartConfig} className="h-64 w-full">
|
|
<BarChart
|
|
data={chartData}
|
|
margin={{ top: 10, right: 10, left: 0, bottom: 0 }}
|
|
>
|
|
<CartesianGrid strokeDasharray="3 3" vertical={false} />
|
|
<XAxis
|
|
dataKey="month"
|
|
axisLine={false}
|
|
tickLine={false}
|
|
tickMargin={8}
|
|
fontSize={12}
|
|
/>
|
|
<YAxis
|
|
axisLine={false}
|
|
tickLine={false}
|
|
tickMargin={8}
|
|
fontSize={10}
|
|
width={48}
|
|
tickFormatter={(value) =>
|
|
compactCurrencyFormatter.format(Number(value))
|
|
}
|
|
/>
|
|
<ChartTooltip
|
|
content={
|
|
<ChartTooltipContent
|
|
formatter={(value) =>
|
|
currencyFormatter.format(Number(value))
|
|
}
|
|
/>
|
|
}
|
|
cursor={{ fillOpacity: 0.05 }}
|
|
/>
|
|
<Bar
|
|
dataKey="value"
|
|
fill="var(--color-value)"
|
|
radius={[4, 4, 0, 0]}
|
|
/>
|
|
</BarChart>
|
|
</ChartContainer>
|
|
</CardContent>
|
|
</Card>
|
|
);
|
|
};
|
|
|
|
export { ChartCard3 };
|