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

188 lines
5.3 KiB
TypeScript

"use client";
import { Area, AreaChart, CartesianGrid, 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 ChartCard9Props {
title?: string;
description?: string;
className?: string;
}
const monthLabel = (monthIndex: number) =>
new Intl.DateTimeFormat("fa-IR", { month: "short" }).format(
new Date(2025, monthIndex, 1),
);
const numberFormatter = new Intl.NumberFormat("fa-IR", {
maximumFractionDigits: 0,
});
const compactNumberFormatter = new Intl.NumberFormat("fa-IR", {
notation: "compact",
maximumFractionDigits: 1,
});
const chartData = [
{ month: monthLabel(0), desktop: 186, mobile: 80, tablet: 45 },
{ month: monthLabel(1), desktop: 305, mobile: 200, tablet: 65 },
{ month: monthLabel(2), desktop: 237, mobile: 120, tablet: 55 },
{ month: monthLabel(3), desktop: 273, mobile: 190, tablet: 70 },
{ month: monthLabel(4), desktop: 209, mobile: 130, tablet: 50 },
{ month: monthLabel(5), desktop: 214, mobile: 140, tablet: 60 },
{ month: monthLabel(6), desktop: 256, mobile: 165, tablet: 72 },
{ month: monthLabel(7), desktop: 289, mobile: 180, tablet: 68 },
];
const chartConfig = {
desktop: {
label: "دسکتاپ",
color: "var(--chart-1)",
},
mobile: {
label: "موبایل",
color: "var(--chart-2)",
},
tablet: {
label: "تبلت",
color: "var(--chart-3)",
},
} satisfies ChartConfig;
const ChartCard9 = ({
title = "منابع ترافیک",
description = "بازدیدکنندگان به تفکیک نوع دستگاه در طول زمان",
className,
}: ChartCard9Props) => {
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">
<AreaChart
data={chartData}
margin={{ top: 10, right: 10, left: 0, bottom: 0 }}
>
<defs>
<linearGradient id="fillDesktop9" x1="0" y1="0" x2="0" y2="1">
<stop
offset="0%"
stopColor="var(--color-desktop)"
stopOpacity={0.4}
/>
<stop
offset="100%"
stopColor="var(--color-desktop)"
stopOpacity={0.1}
/>
</linearGradient>
<linearGradient id="fillMobile9" x1="0" y1="0" x2="0" y2="1">
<stop
offset="0%"
stopColor="var(--color-mobile)"
stopOpacity={0.4}
/>
<stop
offset="100%"
stopColor="var(--color-mobile)"
stopOpacity={0.1}
/>
</linearGradient>
<linearGradient id="fillTablet9" x1="0" y1="0" x2="0" y2="1">
<stop
offset="0%"
stopColor="var(--color-tablet)"
stopOpacity={0.4}
/>
<stop
offset="100%"
stopColor="var(--color-tablet)"
stopOpacity={0.1}
/>
</linearGradient>
</defs>
<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={40}
tickFormatter={(value) =>
compactNumberFormatter.format(Number(value))
}
/>
<ChartTooltip
content={
<ChartTooltipContent
formatter={(value) =>
numberFormatter.format(Number(value))
}
/>
}
cursor={{ stroke: "var(--border)", strokeDasharray: "4 4" }}
/>
<ChartLegend content={<ChartLegendContent />} />
<Area
type="monotone"
dataKey="tablet"
stackId="1"
stroke="var(--color-tablet)"
fill="url(#fillTablet9)"
strokeWidth={2}
/>
<Area
type="monotone"
dataKey="mobile"
stackId="1"
stroke="var(--color-mobile)"
fill="url(#fillMobile9)"
strokeWidth={2}
/>
<Area
type="monotone"
dataKey="desktop"
stackId="1"
stroke="var(--color-desktop)"
fill="url(#fillDesktop9)"
strokeWidth={2}
/>
</AreaChart>
</ChartContainer>
</CardContent>
</Card>
);
};
export { ChartCard9 };