enoughtools

Chart

Component

About

A themeable chart container that wraps Recharts to render bar, line, and other data visualizations with custom tooltips, legends, and CSS-variable-driven series colors.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Chart to your project and fits it to your theme.

Code

How Chart is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";

import * as React from "react";
import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@/components/ui/chart";
import {
  Card,
  CardContent,
  CardDescription,
  CardHeader,
  CardTitle,
} from "@/components/ui/chart-utils/card";
import * as Recharts from "recharts";

const visitors = [
  { month: "Jan", desktop: 186, mobile: 80 },
  { month: "Feb", desktop: 305, mobile: 200 },
  { month: "Mar", desktop: 237, mobile: 120 },
  { month: "Apr", desktop: 173, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "Jun", desktop: 214, mobile: 140 },
];

const visitorConfig = {
  desktop: { label: "Desktop", color: "var(--color-accent)" },
  mobile: { label: "Mobile", color: "var(--color-ok)" },
} satisfies ChartConfig;

function ChartData() {
  return (
    <details className="mt-4 font-sans text-sm text-text-2">
      <summary className="cursor-pointer rounded-sm font-medium focus-visible:outline-2 focus-visible:outline-accent">
        View chart data
      </summary>
      <div className="mt-3 overflow-auto">
        <table className="w-full text-start tabular-nums">
          <caption className="sr-only">Visitors by month and device</caption>
          <thead>
            <tr>
              <th scope="col" className="py-2 text-start">
                Month
              </th>
              <th scope="col" className="text-end">
                Desktop
              </th>
              <th scope="col" className="text-end">
                Mobile
              </th>
            </tr>
          </thead>
          <tbody>
            {visitors.map((row) => (
              <tr key={row.month} className="border-t border-hairline">
                <th scope="row" className="py-2 text-start font-normal">
                  {row.month}
                </th>
                <td className="text-end">{row.desktop}</td>
                <td className="text-end">{row.mobile}</td>
              </tr>
            ))}
          </tbody>
        </table>
      </div>
    </details>
  );
}

export default function ChartLineDemo() {
  return (
    <Card className="w-[min(640px,calc(100vw-48px))]">
      <CardHeader>
        <CardTitle>Mobile traffic</CardTitle>
        <CardDescription>
          A six month trend with keyboard accessible points
        </CardDescription>
      </CardHeader>
      <CardContent>
        <figure>
          <ChartContainer
            config={visitorConfig}
            className="h-64"
            role="group"
            aria-label="Monthly mobile visitors"
          >
            <Recharts.LineChart
              accessibilityLayer
              data={visitors}
              margin={{ top: 12, right: 12 }}
            >
              <Recharts.CartesianGrid vertical={false} />
              <Recharts.XAxis
                dataKey="month"
                axisLine={false}
                tickLine={false}
                tickMargin={10}
              />
              <Recharts.YAxis axisLine={false} tickLine={false} width={36} />
              <ChartTooltip
                content={<ChartTooltipContent indicator="dashed" />}
              />
              <Recharts.Line
                dataKey="mobile"
                stroke="var(--color-mobile)"
                strokeWidth={2}
                dot={{ r: 4 }}
                isAnimationActive={false}
              />
            </Recharts.LineChart>
          </ChartContainer>
          <figcaption className="mt-4 font-sans text-sm text-text-3">
            Mobile visits peaked at 200 in February and finished at 140 in June.
          </figcaption>
          <ChartData />
        </figure>
      </CardContent>
    </Card>
  );
}

Dependencies

More by enoughtools

View all
  • Conversation Bubble

    Conversation Bubble

  • Tool Row

    Tool Row

  • Sidebar

    Sidebar

  • Group Label

    Group Label

  • Callout

    Callout