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

167 lines
4.1 KiB
TypeScript

"use client";
import {
CartesianGrid,
Scatter,
ScatterChart,
XAxis,
YAxis,
ZAxis,
} 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 ChartCard24Props {
title?: string;
description?: string;
className?: string;
}
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 numberFormatter = new Intl.NumberFormat("fa-IR", {
maximumFractionDigits: 0,
});
const dataA = [
{ x: 100, y: 200, z: 200 },
{ x: 120, y: 100, z: 260 },
{ x: 170, y: 300, z: 400 },
{ x: 140, y: 250, z: 280 },
{ x: 150, y: 400, z: 500 },
{ x: 110, y: 280, z: 200 },
];
const dataB = [
{ x: 200, y: 260, z: 240 },
{ x: 240, y: 290, z: 220 },
{ x: 190, y: 290, z: 250 },
{ x: 198, y: 250, z: 210 },
{ x: 180, y: 280, z: 260 },
{ x: 210, y: 220, z: 230 },
];
const chartConfig = {
groupA: {
label: "گروه الف",
color: "var(--chart-1)",
},
groupB: {
label: "گروه ب",
color: "var(--chart-2)",
},
} satisfies ChartConfig;
const ChartCard24 = ({
title = "بخش‌های بازار",
description = "قیمت، حجم و درآمد به تفکیک بخش",
className,
}: ChartCard24Props) => {
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">
<ScatterChart margin={{ top: 10, right: 10, left: 0, bottom: 0 }}>
<CartesianGrid strokeDasharray="3 3" />
<XAxis
type="number"
dataKey="x"
axisLine={false}
tickLine={false}
tickMargin={8}
fontSize={10}
width={52}
tickFormatter={(value) =>
currencyFormatter.format(Number(value))
}
/>
<YAxis
type="number"
dataKey="y"
axisLine={false}
tickLine={false}
tickMargin={8}
fontSize={10}
width={40}
tickFormatter={(value) => numberFormatter.format(Number(value))}
/>
<ZAxis type="number" dataKey="z" range={[40, 400]} />
<ChartTooltip
cursor={{ strokeDasharray: "3 3" }}
content={
<ChartTooltipContent
formatter={(value, name) => {
if (name === "x") {
return `قیمت: ${currencyFormatter.format(Number(value))}`;
}
if (name === "y") {
return `حجم: ${numberFormatter.format(Number(value))}`;
}
if (name === "z") {
return `درآمد: ${compactCurrencyFormatter.format(
Number(value) * 1000,
)}`;
}
return `${name}: ${value}`;
}}
/>
}
/>
<ChartLegend content={<ChartLegendContent />} />
<Scatter
name="groupA"
data={dataA}
fill="var(--color-groupA)"
fillOpacity={0.7}
/>
<Scatter
name="groupB"
data={dataB}
fill="var(--color-groupB)"
fillOpacity={0.7}
/>
</ScatterChart>
</ChartContainer>
</CardContent>
</Card>
);
};
export { ChartCard24 };