Faber UI
Components

Chart

A Recharts wrapper with tooltip, legend, and style helpers.

Chart is a thin wrapper around Recharts. It provides a ChartContainer that reads a config object, plus tooltip and legend components styled to match the rest of the UI.

Installation

Terminal
pnpm dlx shadcn@latest add https://faber-ui.vercel.app/r/chart.json

Usage

Chart components require "use client" because Recharts uses React context internally.

typescript
"use client";

import {
  Bar,
  BarChart,
  CartesianGrid,
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  XAxis,
  type ChartConfig,
} from "@/components/ui/chart";

const chartData = [
  { month: "January", desktop: 186 },
  { month: "February", desktop: 305 },
  { month: "March", desktop: 237 },
];

const chartConfig = {
  desktop: {
    label: "Desktop",
    color: "var(--chart-1)",
  },
} satisfies ChartConfig;

export default function Example() {
  return (
    <ChartContainer config={chartConfig} className="h-[200px] w-full">
      <BarChart data={chartData}>
        <CartesianGrid vertical={false} />
        <XAxis dataKey="month" tickLine={false} axisLine={false} />
        <ChartTooltip content={<ChartTooltipContent />} />
        <Bar dataKey="desktop" fill="var(--color-desktop)" radius={4} />
      </BarChart>
    </ChartContainer>
  );
}

Examples

Bar chart

API

Each part forwards every prop of what it is built on, including className and render where Base UI supports it. The props column lists only what Faber UI adds on top.

PartBuilt onProps
ChartContainerdata-slot="chart"<div>HTML
  • configChartConfig
  • childrenReact.ComponentProps< typeof RechartsPrimitive.ResponsiveContainer >["children"]
  • initialDimension? = INITIAL_DIMENSION{ width: number; height: number; }
ChartStyle<style>HTML
  • idstring
  • configChartConfig
ChartTooltipRechartsPrimitive.Tooltiprecharts—
ChartTooltipContent<div>HTML
  • hideLabel? = falseboolean
  • hideIndicator? = falseboolean
  • indicator? = "dot""line" | "dot" | "dashed"
  • nameKey?string
  • labelKey?string
ChartLegendRechartsPrimitive.Legendrecharts—
ChartLegendContent<div>HTML
  • hideIcon? = falseboolean
  • nameKey?string
AreaArearecharts—
AreaChartAreaChartrecharts—
BarBarrecharts—
BarChartBarChartrecharts—
CartesianGridCartesianGridrecharts—
CellCellrecharts—
LineLinerecharts—
LineChartLineChartrecharts—
PiePierecharts—
PieChartPieChartrecharts—
PolarAngleAxisPolarAngleAxisrecharts—
PolarGridPolarGridrecharts—
RadialBarRadialBarrecharts—
RadialBarChartRadialBarChartrecharts—
RadarRadarrecharts—
RadarChartRadarChartrecharts—
ReferenceLineReferenceLinerecharts—
XAxisXAxisrecharts—
YAxisYAxisrecharts—

Changelog

  1. v0.3.0ChartContainer accepts only color values made of safe characters, closing an injection path through the generated style tag.patch
  2. v0.1.0Accessibility, correctness, and token fixes across the kit, from a full code-smell audit.minor
Full Chart history

Last updated on

On this page