|
| 1 | +"use client" |
| 2 | + |
| 3 | +import { TrendingUp } from "lucide-react" |
| 4 | +import { CartesianGrid, Line, LineChart, XAxis } from "recharts" |
| 5 | + |
| 6 | +import { |
| 7 | + Card, |
| 8 | + CardContent, |
| 9 | + CardDescription, |
| 10 | + CardFooter, |
| 11 | + CardHeader, |
| 12 | + CardTitle, |
| 13 | +} from "@/components/ui/card" |
| 14 | +import { |
| 15 | + ChartContainer, |
| 16 | + ChartTooltip, |
| 17 | + ChartTooltipContent, |
| 18 | + type ChartConfig, |
| 19 | +} from "@/components/ui/chart" |
| 20 | + |
| 21 | +export const description = "A multiple line chart" |
| 22 | + |
| 23 | +const chartData = [ |
| 24 | + { month: "January", desktop: 186, mobile: 80 }, |
| 25 | + { month: "February", desktop: 305, mobile: 200 }, |
| 26 | + { month: "March", desktop: 237, mobile: 120 }, |
| 27 | + { month: "April", desktop: 73, mobile: 190 }, |
| 28 | + { month: "May", desktop: 209, mobile: 130 }, |
| 29 | + { month: "June", desktop: 214, mobile: 140 }, |
| 30 | +] |
| 31 | + |
| 32 | +const chartConfig = { |
| 33 | + desktop: { |
| 34 | + label: "Desktop", |
| 35 | + color: "var(--chart-1)", |
| 36 | + }, |
| 37 | + mobile: { |
| 38 | + label: "Mobile", |
| 39 | + color: "var(--chart-2)", |
| 40 | + }, |
| 41 | +} satisfies ChartConfig |
| 42 | + |
| 43 | + |
| 44 | + |
| 45 | +export function ExampleChart() { |
| 46 | + return ( |
| 47 | + <Card> |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + <CardHeader> |
| 52 | + <CardTitle>Line Chart - Multiple</CardTitle> |
| 53 | + <CardDescription>January - June 2024</CardDescription> |
| 54 | + </CardHeader> |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | + <CardContent> |
| 59 | + <ChartContainer config={chartConfig}> |
| 60 | + <LineChart |
| 61 | + accessibilityLayer |
| 62 | + data={chartData} |
| 63 | + margin={{ |
| 64 | + left: 12, |
| 65 | + right: 12, |
| 66 | + }} |
| 67 | + > |
| 68 | + <CartesianGrid vertical={false} /> |
| 69 | + <XAxis |
| 70 | + dataKey="month" |
| 71 | + tickLine={false} |
| 72 | + axisLine={false} |
| 73 | + tickMargin={8} |
| 74 | + tickFormatter={(value) => value.slice(0, 3)} |
| 75 | + /> |
| 76 | + <ChartTooltip cursor={false} content={<ChartTooltipContent />} /> |
| 77 | + <Line |
| 78 | + dataKey="desktop" |
| 79 | + type="monotone" |
| 80 | + stroke="var(--color-desktop)" |
| 81 | + strokeWidth={2} |
| 82 | + dot={false} |
| 83 | + /> |
| 84 | + <Line |
| 85 | + dataKey="mobile" |
| 86 | + type="monotone" |
| 87 | + stroke="var(--color-mobile)" |
| 88 | + strokeWidth={2} |
| 89 | + dot={false} |
| 90 | + /> |
| 91 | + </LineChart> |
| 92 | + </ChartContainer> |
| 93 | + </CardContent> |
| 94 | + |
| 95 | + |
| 96 | + |
| 97 | + <CardFooter> |
| 98 | + <div className="flex w-full items-start gap-2 text-sm"> |
| 99 | + <div className="grid gap-2"> |
| 100 | + <div className="flex items-center gap-2 leading-none font-medium"> |
| 101 | + Trending up by 5.2% this month <TrendingUp className="h-4 w-4" /> |
| 102 | + </div> |
| 103 | + <div className="text-muted-foreground flex items-center gap-2 leading-none"> |
| 104 | + Showing total visitors for the last 6 months |
| 105 | + </div> |
| 106 | + </div> |
| 107 | + </div> |
| 108 | + </CardFooter> |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + </Card> |
| 113 | + ) |
| 114 | +} |
0 commit comments