Skip to content
All components
Data display

Chart

Give Recharts visualizations one shared series configuration so labels, colors, tooltips and legends agree, while the consumer supplies a title, a takeaway and a durable data alternative.

Recharts with a config object, so a series keeps one color everywhere.

Installation

tdpxl is not an npm dependency of your app. The @tdpxl/cli command (not published to npm yet) copies the source into your project, with the registry items and npm packages it imports.

npx @tdpxl/cli add chart

Then import it from @/components/ui/chart. New project? Start with the installation guide.

Examples

Each example is one branch of the official demo, rendered in its own frame. The code is that branch as you would write it, with imports pointing at the default install paths.

With data table

Pair a chart with a written summary and the same data as a table. The figure caption names the chart, the summary states the takeaway and a disclosure holds the full values. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  CartesianGrid,
  Line,
  LineChart,
  XAxis,
  YAxis,
} from "recharts"

import {
  ChartContainer,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@/components/ui/chart"

import {
  Table,
  TableBody,
  TableCaption,
  TableCell,
  TableHead,
  TableHeader,
  TableRow,
} from "@/components/ui/table"

const data = [
  { month: "Jan", desktop: 186, mobile: 80 },
  { month: "Feb", desktop: 305, mobile: 200 },
  { month: "Mar", desktop: 237, mobile: 120 },
  { month: "Apr", desktop: 273, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "Jun", desktop: 314, mobile: 240 },
]

const config = {
  desktop: { label: "Desktop", color: "var(--color-chart-1)" },
  mobile: { label: "Mobile", color: "var(--color-chart-2)" },
} satisfies ChartConfig

const signups = [
  { week: "Week 1", signups: 120 },
  { week: "Week 2", signups: 148 },
  { week: "Week 3", signups: 0 },
  { week: "Week 4", signups: 164 },
  { week: "Week 5", signups: 191 },
  { week: "Week 6", signups: 236 },
]

const signupConfig = {
  signups: { label: "Sign-ups", color: "var(--color-chart-1)" },
} satisfies ChartConfig

export function ChartWithDataTable() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-12">
      <figure className="flex w-full flex-col gap-3">
        <figcaption className="flex flex-col gap-1">
          <span className="text-label-md text-strong-950">Weekly sign-ups</span>
          <span className="text-paragraph-sm text-sub-600">
            Sign-ups nearly doubled over six weeks, from 120 to 236. Week 3 had
            none because registration was paused for maintenance.
          </span>
        </figcaption>
        <ChartContainer config={signupConfig} className="h-56 w-full">
          <LineChart data={signups} margin={{ left: 4, right: 12 }}>
            <CartesianGrid vertical={false} />
            <XAxis dataKey="week" tickLine={false} axisLine={false} />
            <YAxis width={32} tickLine={false} axisLine={false} />
            <ChartTooltip content={<ChartTooltipContent indicator="line" />} />
            <Line
              dataKey="signups"
              type="monotone"
              stroke="var(--color-signups)"
              strokeWidth={2}
              dot={{ r: 3 }}
            />
          </LineChart>
        </ChartContainer>
        <details className="text-paragraph-sm text-sub-600">
          <summary className="cursor-pointer text-label-sm text-strong-950">
            Show the data as a table
          </summary>
          <div className="mt-3">
            <Table>
              <TableCaption>Weekly sign-ups, the same values as the chart.</TableCaption>
              <TableHeader>
                <TableRow>
                  <TableHead scope="col">Week</TableHead>
                  <TableHead scope="col" className="text-right">Sign-ups</TableHead>
                </TableRow>
              </TableHeader>
              <TableBody>
                {signups.map((row) => (
                  <TableRow key={row.week}>
                    <TableCell>{row.week}</TableCell>
                    <TableCell className="text-right tabular-nums">{row.signups}</TableCell>
                  </TableRow>
                ))}
              </TableBody>
            </Table>
          </div>
        </details>
      </figure>
    </div>
  )
}

Stacked bars

Stack categorical series with a shared legend and tooltip. Each series takes a categorical chart role from the config, so the legend, tooltip and bars agree. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import {
  Bar,
  BarChart,
  CartesianGrid,
  XAxis,
} from "recharts"

import {
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@/components/ui/chart"

const data = [
  { month: "Jan", desktop: 186, mobile: 80 },
  { month: "Feb", desktop: 305, mobile: 200 },
  { month: "Mar", desktop: 237, mobile: 120 },
  { month: "Apr", desktop: 273, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "Jun", desktop: 314, mobile: 240 },
]

const config = {
  desktop: { label: "Desktop", color: "var(--color-chart-1)" },
  mobile: { label: "Mobile", color: "var(--color-chart-2)" },
} satisfies ChartConfig

const tickets = [
  { day: "Mon", billing: 12, technical: 30, account: 8 },
  { day: "Tue", billing: 9, technical: 26, account: 11 },
  { day: "Wed", billing: 15, technical: 22, account: 6 },
  { day: "Thu", billing: 7, technical: 34, account: 9 },
  { day: "Fri", billing: 11, technical: 19, account: 5 },
]

const ticketConfig = {
  billing: { label: "Billing", color: "var(--color-chart-1)" },
  technical: { label: "Technical", color: "var(--color-chart-2)" },
  account: { label: "Account", color: "var(--color-chart-3)" },
} satisfies ChartConfig

export function ChartStackedBars() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-12">
      <figure className="flex w-full flex-col gap-3">
        <figcaption className="text-label-md text-strong-950">
          Support tickets by topic, this week
        </figcaption>
        <ChartContainer config={ticketConfig} className="h-64 w-full">
          <BarChart data={tickets}>
            <CartesianGrid vertical={false} />
            <XAxis dataKey="day" tickLine={false} axisLine={false} />
            <ChartTooltip content={<ChartTooltipContent />} />
            <ChartLegend content={<ChartLegendContent />} />
            <Bar dataKey="billing" stackId="topic" fill="var(--color-billing)" />
            <Bar dataKey="technical" stackId="topic" fill="var(--color-technical)" />
            <Bar dataKey="account" stackId="topic" fill="var(--color-account)" radius={[4, 4, 0, 0]} />
          </BarChart>
        </ChartContainer>
      </figure>
    </div>
  )
}

Donut

Show parts of a whole with labels resolved through nameKey. Each slice reads its color and label from the config entry named by its datum. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { Pie, PieChart } from "recharts"

import {
  ChartContainer,
  ChartLegend,
  ChartLegendContent,
  ChartTooltip,
  ChartTooltipContent,
  type ChartConfig,
} from "@/components/ui/chart"

const data = [
  { month: "Jan", desktop: 186, mobile: 80 },
  { month: "Feb", desktop: 305, mobile: 200 },
  { month: "Mar", desktop: 237, mobile: 120 },
  { month: "Apr", desktop: 273, mobile: 190 },
  { month: "May", desktop: 209, mobile: 130 },
  { month: "Jun", desktop: 314, mobile: 240 },
]

const config = {
  desktop: { label: "Desktop", color: "var(--color-chart-1)" },
  mobile: { label: "Mobile", color: "var(--color-chart-2)" },
} satisfies ChartConfig

const channels = [
  { channel: "direct", visits: 420, fill: "var(--color-direct)" },
  { channel: "search", visits: 610, fill: "var(--color-search)" },
  { channel: "referral", visits: 180, fill: "var(--color-referral)" },
  { channel: "email", visits: 95, fill: "var(--color-email)" },
]

const channelConfig = {
  visits: { label: "Visits" },
  direct: { label: "Direct", color: "var(--color-chart-1)" },
  search: { label: "Search", color: "var(--color-chart-2)" },
  referral: { label: "Referral", color: "var(--color-chart-3)" },
  email: { label: "Email", color: "var(--color-chart-4)" },
} satisfies ChartConfig

export function ChartDonut() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-12">
      <figure className="flex w-full flex-col gap-3">
        <figcaption className="text-label-md text-strong-950">
          Visits by channel, last 30 days
        </figcaption>
        <ChartContainer config={channelConfig} className="mx-auto aspect-square h-72 w-full max-w-xs">
          <PieChart>
            <ChartTooltip content={<ChartTooltipContent nameKey="channel" hideLabel />} />
            <Pie data={channels} dataKey="visits" nameKey="channel" innerRadius={56} strokeWidth={2} />
            <ChartLegend content={<ChartLegendContent nameKey="channel" />} />
          </PieChart>
        </ChartContainer>
      </figure>
    </div>
  )
}

No data

Replace an empty chart with an explanation. An empty state says why there is nothing to plot and when the chart will appear, instead of drawing empty axes. Preserves the complete example's required parts, labels and providers. The example's local state remains owned by that composition.

"use client"

import { ChartNoAxesColumnIcon } from "lucide-react"

import {
  Empty,
  EmptyDescription,
  EmptyMedia,
  EmptyTitle,
} from "@/components/ui/empty"

export function ChartNoData() {
  return (
    <div className="flex w-full max-w-xl flex-col gap-12">
      <figure className="flex w-full flex-col gap-3">
        <figcaption className="text-label-md text-strong-950">
          Refunds by month
        </figcaption>
        <Empty className="min-h-56">
          <EmptyMedia>
            <ChartNoAxesColumnIcon aria-hidden="true" />
          </EmptyMedia>
          <EmptyTitle>No refunds yet</EmptyTitle>
          <EmptyDescription>
            The chart appears once the first refund is issued.
          </EmptyDescription>
        </Empty>
      </figure>
    </div>
  )
}

API reference

Generated from the component's TypeScript signatures. Inherited DOM and primitive props are listed separately.

ChartContainer

Provide shared configuration, tooltip, and legend primitives for Recharts visualizations.

ChartContainer props
PropTypeDefaultDescription
inputMode"search" | "text" | "none" | "tel" | "url" | "email" | "numeric" | "decimal" | undefined—Hints at the type of data that might be entered by the user while editing the element or its contents
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
children(required)React.ReactNode—Content rendered by this part. Preserve the required child composition shown in the complete example.
config(required)ChartConfig—Series metadata keyed by series identifier. Supplies labels, icons and colors shared by the chart, tooltip and legend.
Inherited props (13)
ChartContainer inherited props
PropTypeDefaultDescription
refReact.Ref<HTMLDivElement> | undefined—Allows getting a ref to the component instance. Once the component unmounts, React will set ref.current to null (or call the ref with null if you passed a callback ref).
defaultCheckedboolean | undefined—Initial checked state for a control supporting uncontrolled selection. Inherited DOM typing does not give a layout wrapper checkbox behavior.
defaultValuestring | number | readonly string[] | undefined—Initial value for a control supporting uncontrolled state. Inherited DOM typing alone does not give a layout wrapper input behavior.
autoFocusboolean | undefined—Request automatic focus when the element mounts or the primitive opens, according to its source behavior. Choose initial focus deliberately in context.
classNamestring | undefined—Additional classes for this part. Preserve contrast, visible focus and responsive content when adapting styles.
idstring | undefined—Stable DOM identifier used by labels, descriptions or other explicit associations.
roleReact.AriaRole | undefined—Semantic role appropriate to the rendered element. Preserve required relationships and keyboard behavior.
onFocusReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlurReact.FocusEventHandler<HTMLDivElement> | undefined—Receive the native blur event when focus leaves this control.
onChangeReact.ChangeEventHandler<HTMLDivElement, Element> | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDownReact.KeyboardEventHandler<HTMLDivElement> | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onClickReact.MouseEventHandler<HTMLDivElement> | undefined—Receive activation events. The consumer owns the action performed and its result.
onSelectReact.ReactEventHandler<HTMLDivElement> | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.

ChartLegend

The ChartLegend part of chart. Use it with the complete source composition and preserve its required parent context.

ChartLegend props
PropTypeDefaultDescription
aria-describedbystring | undefined—Identifies the element (or elements) that describes the object.
aria-invalidboolean | "false" | "true" | "grammar" | "spelling" | undefined—Indicates the entered value does not conform to the format expected by the application.
aria-labelstring | undefined—Defines a string value that labels the current element.
aria-labelledbystring | undefined—Identifies the element (or elements) that labels the current element.
childrenReactNode—Represents all of the things React can render.
onClick((data: import("recharts").LegendPayload, index: number, event: MouseEvent<HTMLElement>) => void) | undefined—The customized event handler of click on the items in this group
iconSizenumber | undefined—The size of icon in each legend item.
iconTypeimport("recharts").LegendType | undefined—The type of icon in each legend item.
inactiveColorstring | undefined—The color of the icon when the item is inactive.
formatterimport("recharts").Formatter | undefined—Function to customize how content is serialized before rendering. This should return HTML elements, or strings.
labelStyleCSSProperties | undefined—Style of individual items inside the Legend, a <span> element. These show the data label (name, or dataKey) and value. If a chart has multiple graphical items then the Legend renders multiple item and each of them gets this itemStyle applied. Pie charts render multiple labels from a single data series. Note that this is different from {@link Tooltip }: - in Tooltip: "labelStyle" styles the title / header - in Tooltip: "itemStyle" styles the individual data points - in Legend: "labelStyle" styles the individual data points Beware of the naming inconsistency!
contentimport("recharts").ContentType | undefined—Renders the content of the legend. This should return HTML elements, not SVG elements. - If not set, the {@link DefaultLegendContent } component is used. - If set to a React element, this element will be cloned and extra props will be passed in. - If set to a function, the function will be called and should return HTML elements.
layout"auto" | import("recharts").CartesianLayout | undefined—The layout of legend items inside the legend container. When auto then the layout is decided based on the position prop: - in left|right positions, the layout is vertical - otherwise horizontal - if position is undefined, also horizontal auto value is new since 3.10
wrapperStyleCSSProperties | undefined—CSS styles to be applied to the wrapper div element.
widthstring | number | undefined—Width of the legend. Accept CSS style string values like 100% or fit-content, or number values like 400.
heightstring | number | undefined—Height of the legend. Accept CSS style string values like 100% or fit-content, or number values like 400.
portalHTMLElement | null | undefined—If portal is defined, then Legend will use this element as a target for rendering using React Portal. If this is undefined then Legend renders inside the recharts-wrapper element.
itemSorterimport("recharts").LegendItemSorter | null | undefined—Sorts Legend items. Defaults to value which means it will sort alphabetically by the label. If null is provided then the payload is not sorted. Be aware that without sort, the order of items may change between renders!
positionimport("recharts").CartesianPosition | undefined—The position of the legend relative to the chart. If this is defined, it overrides align and verticalAlign.
offsetnumber | undefined—The offset to the specified position. Direction of the offset depends on the position.
Inherited props (9)
ChartLegend inherited props
PropTypeDefaultDescription
dangerouslySetInnerHTML{ __html: string; } | undefined—Native raw-HTML escape hatch. It replaces normal child rendering; use only trusted or appropriately sanitized content.
onFocus((data: import("recharts").LegendPayload, index: number, event: FocusEvent<ReactElement<unknown, string | JSXElementConstructor<any>>, Element>) => void) | undefined—Receive the native focus event. Preserve the component's existing keyboard and focus behavior.
onBlur((data: import("recharts").LegendPayload, index: number, event: FocusEvent<ReactElement<unknown, string | JSXElementConstructor<any>>, Element>) => void) | undefined—Receive the native blur event when focus leaves this control.
onChange((data: import("recharts").LegendPayload, index: number, event: FormEvent<ReactElement<unknown, string | JSXElementConstructor<any>>>) => void) | undefined—Receive the native change event; read the actual control value or checked state from its event target.
onKeyDown((data: import("recharts").LegendPayload, index: number, event: KeyboardEvent<ReactElement<unknown, string | JSXElementConstructor<any>>>) => void) | undefined—Receive keyboard events. Preserve built-in keyboard behavior unless deliberately implementing an accessible alternative.
onSelect((data: import("recharts").LegendPayload, index: number, event: SyntheticEvent<ReactElement<unknown, string | JSXElementConstructor<any>>, Event>) => void) | undefined—Handle the selection event defined by this part's source signature. DOM text-selection events differ from menu or command activation callbacks.
alignimport("recharts").HorizontalAlignmentType | undefined—Horizontal alignment of the Recharts legend within its chart layout.
payloadUniqByimport("recharts").UniqueOption<import("recharts").LegendPayload> | undefined—Recharts rule for identifying unique payload entries in a tooltip or legend.
verticalAlignimport("recharts").VerticalAlignmentType | undefined—Vertical placement of the chart legend within its available layout.

ChartLegendContent

Content region within the root composition. Keep required providers, labels and related controls from the complete example.

ChartLegendContent props
PropTypeDefaultDescription
payloadPayloadEntry[] | undefined—Entries supplied by Recharts for the current tooltip or legend. Keep series identifiers aligned with ChartConfig.
classNamestring | undefined—Additional classes for this part. Preserve focus visibility, contrast and content reflow when adapting styles.
verticalAlign"top" | "bottom" | "middle" | undefined"bottom"Place the legend above, below or in the middle of its chart layout.
hideIconboolean | undefinedfalseHide the legend's series icon or fallback color marker; text labels remain visible.
nameKeystring | undefined—Payload field used to resolve the series label and configured icon/color.

ChartTooltip

The ChartTooltip part of chart. Use it with the complete source composition and preserve its required parent context.

ChartTooltip props
PropTypeDefaultDescription
separatorstring | undefined—The separator between name and value.
formatter(import("recharts").Formatter<ValueType, NameType> & ((value: ValueType, name: NameType, item: TooltipPayloadEntry, index: number, payload: TooltipPayload) => ReactNode | [ReactNode, ReactNode])) | undefined—Function to customize the value in the tooltip. If you return an array, the first entry will be the formatted "value", and the second entry will be the formatted "name"
labelStyleReact.CSSProperties | undefined—"Label" is the tooltip title. Renders once on the top of tooltip and shows categorical axis value. Even if there are multiple graphical items in the chart, only one label gets rendered. Note that "Label" in tooltip is the header, which is different from {@link Legend } where "labelStyle" are the individual items.
contentStyleReact.CSSProperties | undefined—CSS styles to be applied to the wrapper div element.
itemStyleReact.CSSProperties | undefined—Style of individual items inside the tooltip, a <li> element. These show the data label (name, or dataKey) and value. If a chart has multiple graphical items then the Tooltip renders multiple item and each of them gets this itemStyle applied.
labelFormatter(((label: ReactNode, payload: readonly import("recharts").TooltipPayloadEntry<ValueType, NameType>[]) => ReactNode) & ((label: ReactNode, payload: TooltipPayload) => ReactNode)) | undefined—The formatter function of label in tooltip.
itemSorter(TooltipItemSorter<ValueType, NameType> & TooltipItemSorter) | undefined—Sorts tooltip items. Defaults to 'name' which means it sorts alphabetically by graphical item name property.
activeboolean | undefined—If true, then Tooltip is always displayed, once an activeIndex is set by mouse over, or programmatically. If false, then Tooltip is never displayed. If undefined, Recharts will control when the Tooltip displays. This includes mouse and keyboard controls.
allowEscapeViewBoxAllowInDimension | undefined—This option allows the tooltip to extend beyond the viewBox of the chart itself.
animationDurationnumber | undefined—Specifies the duration of animation, the unit of this option is ms.
animationEasingEasingInput | undefined—The type of easing function.
axisIdAxisId | undefined—Tooltip always attaches itself to the "Tooltip" axis. Which axis is it? Depends on the layout: - horizontal layout -> X axis - vertical layout -> Y axis - radial layout -> radial axis - centric layout -> angle axis Tooltip will use the default axis for the layout, unless you specify an axisId.
contentContentType<ValueType, NameType> | undefined—Renders the content of the tooltip. This should return HTML elements, not SVG elements. - If not set, the {@link DefaultTooltipContent } component is used. - If set to a React element, this element will be cloned and extra props will be passed in. - If set to a function, the function will be called and should return HTML elements.
cursorCursorDefinition | undefined—If set false, no cursor will be drawn when tooltip is active. If set a object, the option is the configuration of cursor. If set a React element, the option is the custom react element of drawing cursor.
filterNullboolean | undefined—When an item of the payload has value null or undefined, this item won't be displayed.
includeHiddenboolean | undefined—If true, the tooltip will display information about hidden series. Defaults to false. Interacting with the hide property of Area, Bar, Line, Scatter.
isAnimationActiveboolean | "auto" | undefined—If set false, animation of tooltip will be disabled. If set "auto", the animation will be disabled in SSR and will respect the user's prefers-reduced-motion system preference for accessibility.
offsetnumber | Coordinate | undefined—The offset size between the position of tooltip and the mouse cursor position. When a number is provided, the same offset is applied to both x and y axes. When a Coordinate object is provided, you can specify different offsets for each axis (x and y as numbers)
portalHTMLElement | null | undefined—If portal is defined, then Tooltip will use this element as a target for rendering using React Portal: https://react.dev/reference/react-dom/createPortal If this is undefined then Tooltip renders inside the recharts-wrapper element.
positionPartial<Coordinate> | undefined—If this field is set, the tooltip will be displayed at the specified position regardless of the mouse position. You can set a single field (x or y) and let the other field be calculated automatically based on the mouse position.
sharedboolean | undefined—Defines whether the tooltip is reacting to the current data point, or to all data points at the current axis coordinate. - true: tooltip will appear on top of all bars on an axis tick. - false: tooltip will appear on individual bars. Different chart types allow different modes, and have different defaults.
triggerTooltipTrigger | undefined—If hover then the Tooltip shows on mouse enter and hides on mouse leave. If click then the Tooltip shows after clicking and stays active.
wrapperStyleReact.CSSProperties | undefined—CSS styles to be applied to the wrapper div element.
Inherited props (6)
ChartTooltip inherited props
PropTypeDefaultDescription
wrapperClassNamestring | undefined—Additional classes for the chart tooltip wrapper.
labelClassNamestring | undefined—Additional classes for the chart tooltip label.
defaultIndexnumber | TooltipIndex | undefined—Initial tooltip index passed to Recharts. Use the source-defined index type for the selected chart.
payloadUniqByUniqueOption<TooltipPayloadEntry> | undefined—Recharts rule for identifying unique payload entries in a tooltip or legend.
reverseDirectionAllowInDimension | undefined—Axes on which the Recharts tooltip should reverse its positioning direction.
useTranslate3dboolean | undefined—Use a three-dimensional CSS transform for Recharts tooltip positioning.

ChartTooltipContent

Content region within the root composition. Keep required providers, labels and related controls from the complete example.

ChartTooltipContent props
PropTypeDefaultDescription
activeboolean | undefined—Whether the chart tooltip is active. Tooltip content returns null when inactive or when its payload is empty.
payloadPayloadEntry[] | undefined—Entries supplied by Recharts for the current tooltip or legend. Keep series identifiers aligned with ChartConfig.
labelReact.ReactNode—Chart series label or tooltip heading, resolved through the supplied series configuration.
classNamestring | undefined—Additional classes for this part. Preserve focus visibility, contrast and content reflow when adapting styles.
indicator"line" | "dot" | "dashed" | undefined"dot"Tooltip series-marker shape: dot, line or dashed. This changes presentation, not the series value.
hideLabelboolean | undefinedfalseHide the tooltip heading while retaining its series/value rows.
hideIndicatorboolean | undefinedfalseHide the tooltip's fallback color marker. A configured series icon can still render.
labelKeystring | undefined—Payload field used to resolve the tooltip heading's series configuration.
nameKeystring | undefined—Payload field used to resolve the series label and configured icon/color.
labelClassNamestring | undefined—Additional classes for the tooltip heading. Preserve readable contrast against its surface.
labelFormatter((label: React.ReactNode, payload: PayloadEntry[]) => React.ReactNode) | undefined—Render the tooltip heading from its resolved label and current payload.
formatter((value: unknown, name: string, item: PayloadEntry, index: number, itemPayload: unknown) => React.ReactNode) | undefined—Render a tooltip value row from its value, series name, entry, index and original datum.
colorstring | undefined—CSS color for the configured series, or an explicit tooltip marker override. Preserve contrast and distinguishability.

Accessibility & usage

From registry/ui/chart.meta.json (authored guidance; human review may still be pending). Behavior is checked by Storybook tests, not certified here.

When to use

  • Show a trend, comparison, distribution or part-to-whole relationship where the shape of the data is the message.
  • Several charts on a page should share consistent series names and categorical colors across the chart, tooltip and legend.
  • Dashboards and reports where each chart sits with a title, a one-sentence summary and access to the underlying values.

When not to use

  • One or two numbers; a stat with a label and a comparison sentence is faster to read than a chart.
  • People need exact values or to look up a specific record; use a table (and optionally add a chart next to it).
  • Data with too many categories for the five categorical roles; aggregate into 'Other', use small multiples, or a table.
  • Decoration without a question it answers.

Anatomy

ChartConfig
Object keyed by series id with label, optional icon and color. Becomes scoped CSS variables (--color-<key>) on the container.
ChartContainer
The sized wrapper (aspect-video by default) that provides config context, writes the color variables and renders a Recharts ResponsiveContainer around one chart.
ChartTooltip
Recharts Tooltip, re-exported. Pass content={<ChartTooltipContent />}.
ChartTooltipContent
Tooltip body: optional heading, one row per series with indicator (dot, line, dashed), configured label and formatted value; zero values are shown.
ChartLegend
Recharts Legend, re-exported. Pass content={<ChartLegendContent />}.
ChartLegendContent
Legend row with a color marker or configured icon plus the configured label for each series; nameKey resolves labels for datum-colored charts such as pies.
Recharts chart
The visualization itself (BarChart, LineChart, PieChart…). Recharts owns rendering, tooltip behavior and its keyboard layer.

Keyboard & interaction

  • Recharts 3 enables its accessibility layer by default: the chart surface is focusable, shows a visible focus outline from ChartContainer, and arrow keys move the active tooltip between data points.
  • Pointer hover shows the tooltip for the nearest data point; touch shows it on tap. The tooltip is supplemental: the same values must be available without it.
  • Legends are passive labels here; if you make series toggleable, use real buttons with a pressed state and keep the hidden series announced.
  • Animations come from Recharts; disable or shorten them (isAnimationActive) when the user prefers reduced motion.

Responsive behavior

  • ChartContainer fills its width; give it a height or an aspect ratio so it does not collapse, and let it shrink with the layout (WCAG 1.4.10).
  • At narrow widths reduce tick density (interval, shorter month names) instead of letting labels overlap or rotate into illegibility.
  • Legends wrap onto several lines; keep labels short and place the legend below the chart on small screens.
  • Keep the data alternative reachable on mobile; a collapsible table under the chart works at every width.

Content guidelines

  • Give each chart a visible title that states what is measured and the period ('Weekly sign-ups, last 6 weeks'); a figure with figcaption names it for assistive technology.
  • Add a one-sentence takeaway next to the chart ('Sign-ups nearly doubled…'), and explain gaps or zeros ('Registration was paused in week 3').
  • Label axes and units where they are not obvious; format numbers for the locale and avoid unnecessary decimals.
  • Series labels in the config are short nouns and match the legend and tooltip exactly.
  • Provide a table, a summary list or a download with the same values (data alternative).
  • For no data, show an empty state that says why and when the chart will appear.

Alternatives

  • Table — Exact values and lookups, and the data alternative that should accompany a chart.
  • Progress — A single value toward a known maximum.
  • Empty — What to show instead of an empty chart when there is no data yet.

Resources