ebnsina

Chart

Component

About

A themed chart card with a title, a one-line takeaway, and an SVG plot (bar, line, area, pie, radar, radial) that draws itself in once scrolled into view, with optional center content and a custom tooltip.

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

import Chart from "@/components/ui/chart";
import { barY, defineChart } from "@tanstack/charts";
import { scaleBand } from "@tanstack/charts/scales/band";
import { scaleLinear } from "@tanstack/charts/scales/linear";
import { tooltip } from "@tanstack/charts/tooltip";

const loans = [
  { month: "Jan", loans: 412 },
  { month: "Feb", loans: 486 },
  { month: "Mar", loans: 531 },
  { month: "Apr", loans: 468 },
  { month: "May", loans: 597 },
  { month: "Jun", loans: 642 },
];

const definition = defineChart({
  marks: [barY(loans, { x: "month", y: "loans", radius: 4 })],
  scales: {
    x: {
      scale: () => scaleBand<string>().padding(0.3),
      axis: { label: "Month" },
    },
    y: {
      scale: scaleLinear,
      nice: true,
      grid: true,
      axis: { label: "Loans", ticks: { count: 5 } },
    },
  },
  tooltip,
});

export default function ChartDemo() {
  return (
    <div className="flex w-full items-center justify-center p-10">
      <div className="w-full max-w-xl">
        <Chart
          title="Loans per month"
          description="Loans dipped in April, then rose to their highest in June."
          definition={definition}
        />
      </div>
    </div>
  );
}

Dependencies

More by ebnsina

View all
  • Countdown Timer

    Countdown Timer

    35
  • Video Player

    Video Player

    26
  • Alarm Clock

    Alarm Clock

    24
  • Hourglass Timer

    Hourglass Timer

    19
  • Voice Note

    Voice Note

    19
  • Sortable List

    Sortable List

    17
  • Sign In Auth Card

    Sign In Auth Card

    13
  • Split Button

    Split Button

    13