Chart
Beautiful charts built using Recharts.
When to Use
Use Chart when you need to:
- Visualize quantitative data such as trends, comparisons, or distributions
- Display time-series data with line, area, or bar charts
- Show proportional data with pie or donut charts
- Present multi-series data with legends and interactive tooltips
- Build dashboard widgets with consistent theming via CSS variables
When Not to Use
- Simple numeric values or KPIs without comparison - use a Card with text
- Tabular data where exact values matter more than trends - use Table or Data Table
- Progress toward a single goal - use Progress
- Small inline sparklines or micro-charts where Recharts overhead is unnecessary
Bar Chart
Vertical bar chart with grid, axis labels, and tooltips. Use for comparing discrete categories.
Line Chart
Line chart showing trends over time. Use monotone interpolation for smooth curves.
Area Chart
Stacked area chart for cumulative data. Uses fillOpacity for layered transparency.
Pie Chart
Donut chart with legend showing proportional data. Uses innerRadius for the donut hole.
With Legend
Bar chart with an integrated ChartLegend component for identifying data series.
Horizontal Bar Chart
Horizontal layout with category labels on the Y-axis. Use for long category names.
UX & Design Guidelines
Chart Selection
Use BarChart for comparing discrete categories, LineChart for continuous trends over time, AreaChart for cumulative or stacked volumes, and PieChart for part-to-whole relationships with fewer than 6 segments. Avoid pie charts for more than 6 categories; switch to a horizontal bar chart instead.
Color & Theming
Always use semantic CSS variables (var(--chart-1) through var(--chart-5)) rather than hardcoded hex or OKLCH values. The ChartContainer injects scoped --color-* variables from your config, ensuring consistent theming in light and dark modes. Limit data series to 5 colors to maintain visual clarity.
Responsive Behavior
ChartContainer uses ResponsiveContainer internally, so charts automatically fill their parent width. Always set a fixed height via className="h-[200px]". On small screens, consider hiding axis labels or switching to horizontal bar layouts for better readability.
Data Density & Readability
Use CartesianGrid vertical={false} to reduce visual noise. Abbreviate long axis labels with tickFormatter (e.g., month names to 3 characters). Add tooltips for precise values on hover, and include legends when displaying more than one data series.
Accessibility
Keyboard Navigation
- Tab — Move focus into the chart container
- Arrow Left / Arrow Right — Navigate between data points when
accessibilityLayeris enabled - Enter or Space — Activate tooltip for the focused data point
- Escape — Dismiss active tooltip and return focus to the chart
Screen Reader Support
- Add
accessibilityLayerprop to all chart components for ARIA role announcements - Use descriptive
labelvalues in ChartConfig so screen readers announce meaningful series names - Wrap charts in a
<figure>with a<figcaption>for additional context - Provide a text summary or data table alternative for complex charts
Color Independence
Never rely on color alone to distinguish data series. Always include legends with text labels, use distinct patterns or shapes where possible, and ensure tooltips display the series name. The ChartLegendContent component pairs color swatches with text labels to support colorblind users.
Touch Targets
Tooltips activate on both hover and touch. Set adequate bar width or dot radius so touch targets meet the minimum 44x44px recommendation. For pie charts, use paddingAngle to create visible gaps between segments, making them easier to tap on mobile devices.
ARIA Attributes
{/* Enable keyboard navigation with accessibilityLayer */}
<BarChart accessibilityLayer data={chartData}>
{/* ... */}
</BarChart>
{/* Meaningful labels in config for screen readers */}
const chartConfig = {
desktop: { label: "Desktop Visitors" },
mobile: { label: "Mobile Visitors" },
} satisfies ChartConfig
{/* Wrap chart in a figure with caption */}
<figure role="figure" aria-label="Visitor statistics chart">
<ChartContainer config={chartConfig} className="h-[200px] w-full">
<BarChart accessibilityLayer data={chartData}>
{/* ... */}
</BarChart>
</ChartContainer>
<figcaption className="sr-only">
Bar chart showing desktop and mobile visitors from January to June
</figcaption>
</figure>Related Components
API Reference
The Chart system is composed of several components. ChartContainer is the primary wrapper; ChartConfig defines data series; tooltip and legend components customize interactivity.
ChartContainer
Wrapper that provides chart context, responsive sizing, and CSS variable injection.
| Prop | Type | Default | Description |
|---|---|---|---|
| config | ChartConfig | — | Configuration object with labels, icons, and colors for chart data keys. |
| className | string | — | Additional CSS classes. Must include a height (e.g., h-[200px]). |
| children | ReactNode | — | Recharts components (BarChart, LineChart, etc.) to render inside the container. |
| id | string | auto-generated | Optional ID for the chart container. Used for CSS variable scoping. |
ChartConfig
Configuration object mapping data keys to labels, colors, and optional icons.
| Prop | Type | Default | Description |
|---|---|---|---|
| [key] | { label?: ReactNode; icon?: ComponentType; color?: string; theme?: Record<string, string> } | — | Key matching your data series (e.g., 'desktop', 'mobile'). Each key defines its label, optional icon, and color. |
ChartTooltipContent
Customizable tooltip content rendered inside Recharts Tooltip.
| Prop | Type | Default | Description |
|---|---|---|---|
| indicator | "dot" | "line" | "dashed" | "dot" | Style of the color indicator shown next to each item. |
| hideLabel | boolean | false | Whether to hide the tooltip header label. |
| hideIndicator | boolean | false | Whether to hide the color indicator dot/line. |
| labelKey | string | — | Config key to use for the tooltip label text. |
| nameKey | string | — | Config key to use for item names in the tooltip. |
ChartLegendContent
Custom legend content rendered inside Recharts Legend.
| Prop | Type | Default | Description |
|---|---|---|---|
| hideIcon | boolean | false | Whether to hide the legend icon/color swatch. |
| nameKey | string | — | Config key to use for legend item names. |
| verticalAlign | "top" | "bottom" | "bottom" | Vertical alignment of the legend relative to the chart. |
| className | string | — | Additional CSS classes to apply to the legend container. |