Chart

Displays data visualizations using Recharts with a customizable theme.

data-display
visualization
graphs
statistics

Preview

Code

TSX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import {
      ChartContainer,
      ChartTooltip,
      ChartTooltipContent,
    } from "@/components/ui/chart"
    import {
      LineChart,
      Line,
      XAxis,
      YAxis,
      CartesianGrid,
    } from "recharts"

    export function ChartDemo() {
      const data = [
        { name: "Jan", value: 400 },
        { name: "Feb", value: 300 },
        { name: "Mar", value: 500 },
        { name: "Apr", value: 280 },
        { name: "May", value: 590 },
        { name: "Jun", value: 320 },
      ]

      const config = {
        value: {
          label: "Revenue",
          color: "#0ea5e9",
        },
      }

      return (
        <ChartContainer config={config}>
          <LineChart data={data} margin={{ top: 5, right: 20, bottom: 5, left: 0 }}>
            <CartesianGrid strokeDasharray="3 3" />
            <XAxis dataKey="name" />
            <YAxis />
            <ChartTooltip content={<ChartTooltipContent />} />
            <Line 
              type="monotone" 
              dataKey="value" 
              stroke="var(--color-value, #0ea5e9)" 
              strokeWidth={2} 
              dot={{ r: 4 }}
            />
          </LineChart>
        </ChartContainer>
      )
    }

API Reference

PropTypeDefaultDescription
configChartConfig-Configuration object for chart colors and labels.
childrenReact.ReactNode-Chart component from Recharts library.