Files
reui-blocks/blocks/chart-card6.tsx
T

143 lines
3.7 KiB
TypeScript

"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 ChartCard6Props {
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), current: 186, previous: 165 },
{ month: monthLabel(1), current: 305, previous: 280 },
{ month: monthLabel(2), current: 237, previous: 251 },
{ month: monthLabel(3), current: 273, previous: 240 },
{ month: monthLabel(4), current: 209, previous: 195 },
{ month: monthLabel(5), current: 314, previous: 285 },
];
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 = {
current: {
label: "امسال",
color: "var(--chart-1)",
},
previous: {
label: "سال قبل",
color: "var(--chart-4)",
},
} satisfies ChartConfig;
const ChartCard6 = ({
title = "مقایسه درآمد",
description = "سال جاری در برابر سال قبل",
className,
}: ChartCard6Props) => {
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">
<LineChart
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={{ stroke: "var(--border)", strokeDasharray: "4 4" }}
/>
<ChartLegend content={<ChartLegendContent />} />
<Line
type="monotone"
dataKey="current"
stroke="var(--color-current)"
strokeWidth={2}
dot={{ fill: "var(--color-current)", r: 4 }}
activeDot={{ r: 6 }}
/>
<Line
type="monotone"
dataKey="previous"
stroke="var(--color-previous)"
strokeWidth={2}
strokeDasharray="4 4"
dot={{ fill: "var(--color-previous)", r: 4 }}
activeDot={{ r: 6 }}
/>
</LineChart>
</ChartContainer>
</CardContent>
</Card>
);
};
export { ChartCard6 };