89 lines
2.2 KiB
TypeScript
89 lines
2.2 KiB
TypeScript
"use client"
|
|
|
|
import { CartesianGrid, Line, LineChart, XAxis } from "recharts"
|
|
|
|
import {
|
|
Card,
|
|
CardContent,
|
|
CardDescription,
|
|
CardHeader,
|
|
CardTitle
|
|
} from "@/components/ui/card"
|
|
import {
|
|
ChartContainer,
|
|
ChartTooltip,
|
|
ChartTooltipContent,
|
|
type ChartConfig,
|
|
} from "@/components/ui/chart"
|
|
import { formatCurrency } from "@/lib/formatters"
|
|
|
|
export const description = "Perbandingan Pendapatan vs Laba Bersih per bulan."
|
|
|
|
const chartConfig = {
|
|
revenue: {
|
|
label: "Pendapatan",
|
|
color: "var(--chart-1)",
|
|
},
|
|
profit: {
|
|
label: "Laba Bersih",
|
|
color: "var(--chart-2)",
|
|
},
|
|
} satisfies ChartConfig
|
|
|
|
export function RevenueVsProfitChart({ data }: { data: any[] }) {
|
|
return (
|
|
<Card>
|
|
<CardHeader>
|
|
<CardTitle>Pendapatan vs Laba Bersih</CardTitle>
|
|
<CardDescription>Perbandingan Pendapatan vs Laba Bersih per bulan.</CardDescription>
|
|
</CardHeader>
|
|
<CardContent>
|
|
<ChartContainer config={chartConfig} className="aspect-auto h-[300px] w-full">
|
|
<LineChart
|
|
accessibilityLayer
|
|
data={data}
|
|
margin={{
|
|
left: 12,
|
|
right: 12,
|
|
}}
|
|
>
|
|
<CartesianGrid vertical={false} />
|
|
<XAxis
|
|
dataKey="month"
|
|
tickLine={false}
|
|
axisLine={false}
|
|
tickMargin={8}
|
|
tickFormatter={(value) => value.slice(0, 3)}
|
|
/>
|
|
<ChartTooltip
|
|
cursor={false}
|
|
content={
|
|
<ChartTooltipContent
|
|
formatter={(value, name) => [
|
|
formatCurrency(Number(value)),
|
|
` - ${chartConfig[name as keyof typeof chartConfig]?.label ?? name}`,
|
|
]}
|
|
/>
|
|
}
|
|
/>
|
|
<Line
|
|
dataKey="revenue"
|
|
type="monotone"
|
|
stroke="var(--color-revenue)"
|
|
strokeWidth={2}
|
|
dot={false}
|
|
/>
|
|
<Line
|
|
dataKey="profit"
|
|
type="monotone"
|
|
stroke="var(--color-profit)"
|
|
strokeWidth={2}
|
|
dot={false}
|
|
/>
|
|
</LineChart>
|
|
</ChartContainer>
|
|
</CardContent>
|
|
</Card>
|
|
)
|
|
}
|