|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { TrendingUp } from "lucide-react" |
| 4 | +import { Bar, BarChart, CartesianGrid, XAxis, YAxis } from "recharts" |
| 5 | + |
| 6 | +import { |
| 7 | + Card, |
| 8 | + CardContent, |
| 9 | + CardDescription, |
| 10 | + CardFooter, |
| 11 | + CardHeader, |
| 12 | + CardTitle, |
| 13 | +} from "@/registry/new-york-v4/ui/card" |
| 14 | +import { |
| 15 | + ChartConfig, |
| 16 | + ChartContainer, |
| 17 | + ChartTooltip, |
| 18 | + ChartTooltipContent, |
| 19 | +} from "@/registry/new-york-v4/ui/chart" |
| 20 | + |
| 21 | +const chartData = [ |
| 22 | + { month: "January", desktop: 186, mobile: 80 }, |
| 23 | + { month: "February", desktop: 305, mobile: 200 }, |
| 24 | + { month: "March", desktop: 237, mobile: 120 }, |
| 25 | + { month: "April", desktop: 73, mobile: 190 }, |
| 26 | + { month: "May", desktop: 209, mobile: 130 }, |
| 27 | + { month: "June", desktop: 346, mobile: 140 }, |
| 28 | + { month: "July", desktop: 321, mobile: 275 }, |
| 29 | + { month: "August", desktop: 132, mobile: 95 }, |
| 30 | + { month: "September", desktop: 189, mobile: 225 }, |
| 31 | + { month: "October", desktop: 302, mobile: 248 }, |
| 32 | + { month: "November", desktop: 342, mobile: 285 }, |
| 33 | + { month: "December", desktop: 328, mobile: 290 }, |
| 34 | +] |
| 35 | + |
| 36 | +const chartConfig = { |
| 37 | + desktop: { |
| 38 | + label: "Desktop", |
| 39 | + color: "var(--chart-1)", |
| 40 | + }, |
| 41 | + mobile: { |
| 42 | + label: "Mobile", |
| 43 | + color: "var(--chart-2)", |
| 44 | + }, |
| 45 | +} satisfies ChartConfig |
| 46 | + |
| 47 | +export function ChartRevenue() { |
| 48 | + return ( |
| 49 | + <Card> |
| 50 | + <CardHeader> |
| 51 | + <CardDescription>January - June 2024</CardDescription> |
| 52 | + <CardTitle className="text-3xl font-bold tracking-tight"> |
| 53 | + $45,231.89 |
| 54 | + </CardTitle> |
| 55 | + </CardHeader> |
| 56 | + <CardContent> |
| 57 | + <ChartContainer config={chartConfig} className="aspect-[3/1]"> |
| 58 | + <BarChart |
| 59 | + accessibilityLayer |
| 60 | + data={chartData} |
| 61 | + margin={{ |
| 62 | + left: -16, |
| 63 | + right: 0, |
| 64 | + }} |
| 65 | + > |
| 66 | + <CartesianGrid vertical={false} /> |
| 67 | + <XAxis |
| 68 | + dataKey="month" |
| 69 | + tickLine={false} |
| 70 | + tickMargin={10} |
| 71 | + axisLine={false} |
| 72 | + tickFormatter={(value) => value.slice(0, 3)} |
| 73 | + /> |
| 74 | + <YAxis |
| 75 | + tickLine={false} |
| 76 | + tickMargin={10} |
| 77 | + axisLine={false} |
| 78 | + tickFormatter={(value) => value.toLocaleString()} |
| 79 | + domain={[0, "dataMax"]} |
| 80 | + /> |
| 81 | + <ChartTooltip |
| 82 | + cursor={false} |
| 83 | + content={<ChartTooltipContent hideIndicator />} |
| 84 | + /> |
| 85 | + <Bar |
| 86 | + dataKey="desktop" |
| 87 | + fill="var(--color-desktop)" |
| 88 | + radius={[0, 0, 4, 4]} |
| 89 | + stackId={1} |
| 90 | + /> |
| 91 | + <Bar |
| 92 | + dataKey="mobile" |
| 93 | + fill="var(--color-mobile)" |
| 94 | + radius={[4, 4, 0, 0]} |
| 95 | + stackId={1} |
| 96 | + /> |
| 97 | + </BarChart> |
| 98 | + </ChartContainer> |
| 99 | + </CardContent> |
| 100 | + <CardFooter className="flex-col items-start gap-2 text-sm"> |
| 101 | + <div className="flex gap-2 leading-none font-medium"> |
| 102 | + Trending up by 5.2% this month <TrendingUp className="h-4 w-4" /> |
| 103 | + </div> |
| 104 | + <div className="text-muted-foreground leading-none"> |
| 105 | + Showing total visitors for the last 6 months |
| 106 | + </div> |
| 107 | + </CardFooter> |
| 108 | + </Card> |
| 109 | + ) |
| 110 | +} |
0 commit comments