BarChart
Bar chart component for intuitive data comparison and trend visualization — supports vertical/horizontal layout, grouped/stacked display, and bar labels.
Playground
<Chart config={chartConfig} className="min-h-[200px]">
<BarChart accessibilityLayer data={chartData}>
<CartesianGrid vertical={false} />
<ChartXAxis dataKey="month" tickLine={false} tickMargin={10} axisLine={false} />
<ChartTooltip content={<ChartTooltipContent />} />
<ChartLegend content={<ChartLegendContent />} />
<ChartBar dataKey="desktop" fill="var(--color-desktop)" radius="base" />
<ChartBar dataKey="mobile" fill="var(--color-mobile)" radius="base" />
</BarChart>
</Chart>JSX Composition
Chart.* from this library, and other components from Recharts.
<CartesianGrid /><ChartYAxis /><ChartLegend /><LabelList />Patterns
Main display patterns for BarChart — choose based on your use case.
Default
Basic bar chart with a single series
Multiple Bars
Place multiple series side-by-side for comparison
Stacked
Stack multiple series to visualize totals
Horizontal
Horizontal bar chart (layout="vertical")
Tooltip Styles
Use the indicator prop on ChartTooltipContent to change the tooltip indicator shape.
Dot (default)
Default dot indicator
indicator="dot"Line
Vertical line indicator
indicator="line"Dashed
Dashed line indicator
indicator="dashed"API
Component Structure
Chart— Recharts.BarPropsBar (radius · variant · layout · stackPosition).XAxisX-axis.YAxisY-axis.TooltipTooltip wrapper.TooltipContentPropsTooltip content.LegendLegend wrapper.LegendContentLegend contentProps
Chart
config—ChartConfigChart configuration object (label and color definitions)
children—ReactElementRecharts chart component
idundefinedstringUnique chart ID — used for CSS variable scoping
hoverFadefalsebooleanEnables highlight effect — hovered bar group shown at full color, others faded out
| Name | Type | Default | Description |
|---|---|---|---|
config | ChartConfig | — | Chart configuration object (label and color definitions) |
children | ReactElement | — | Recharts chart component |
id | string | undefined | Unique chart ID — used for CSS variable scoping |
hoverFade | boolean | false | Enables highlight effect — hovered bar group shown at full color, others faded out |
ChartBar
variant"solid""solid" | "outline"Bar style — "outline" shows a thick border with semi-transparent fill
radius"none""none" | "sm" | "base" | "md" | "lg"Corner radius size — named variants matching design tokens (--radius-*)
layout"vertical""vertical" | "horizontal"Chart direction — "horizontal" applies radius to the right side (opposite Y-axis)
stackPosition"top""top" | "bottom"Position in stacked bars — "bottom" applies radius to the bottom
| Name | Type | Default | Description |
|---|---|---|---|
variant | "solid" | "outline" | "solid" | Bar style — "outline" shows a thick border with semi-transparent fill |
radius | "none" | "sm" | "base" | "md" | "lg" | "none" | Corner radius size — named variants matching design tokens (--radius-*) |
layout | "vertical" | "horizontal" | "vertical" | Chart direction — "horizontal" applies radius to the right side (opposite Y-axis) |
stackPosition | "top" | "bottom" | "top" | Position in stacked bars — "bottom" applies radius to the bottom |
ChartTooltipContent
indicator"dot""dot" | "line" | "dashed"Indicator shape
hideLabelfalsebooleanHide the label
hideIndicatorfalsebooleanHide the indicator
colorundefinedstringDirectly sets indicator color — falls back to payload color if not set
labelClassNameundefinedstringCSS class added to the label element
nameKeyundefinedstringName mapping for data key
labelKeyundefinedstringMapping for label key
labelFormatterundefined(value, payload) => ReactNodeCustom label formatter
formatterundefined(value, name, item, index, payload) => ReactNodeCustom value formatter
| Name | Type | Default | Description |
|---|---|---|---|
indicator | "dot" | "line" | "dashed" | "dot" | Indicator shape |
hideLabel | boolean | false | Hide the label |
hideIndicator | boolean | false | Hide the indicator |
color | string | undefined | Directly sets indicator color — falls back to payload color if not set |
labelClassName | string | undefined | CSS class added to the label element |
nameKey | string | undefined | Name mapping for data key |
labelKey | string | undefined | Mapping for label key |
labelFormatter | (value, payload) => ReactNode | undefined | Custom label formatter |
formatter | (value, name, item, index, payload) => ReactNode | undefined | Custom value formatter |
ChartLegendContent
hideIconfalsebooleanHide the icon
nameKeyundefinedstringName mapping for data key
verticalAlign"bottom""top" | "middle" | "bottom"Vertical position — auto-injected from Recharts Legend
align"center""left" | "center" | "right"Horizontal position — auto-injected from Recharts Legend
layout"horizontal""horizontal" | "vertical"Layout direction — auto-injected from Recharts Legend
| Name | Type | Default | Description |
|---|---|---|---|
hideIcon | boolean | false | Hide the icon |
nameKey | string | undefined | Name mapping for data key |
verticalAlign | "top" | "middle" | "bottom" | "bottom" | Vertical position — auto-injected from Recharts Legend |
align | "left" | "center" | "right" | "center" | Horizontal position — auto-injected from Recharts Legend |
layout | "horizontal" | "vertical" | "horizontal" | Layout direction — auto-injected from Recharts Legend |
ChartXAxis / ChartYAxis
tick{ style: { fontSize, fill } }objectAxis label style — applies design tokens by default (--font-size-2xs, --color-text-subtle). Override with a custom object
width (YAxis)"auto"number | "auto"Y-axis width — "auto" adjusts to data. Pass a number for fixed width
...props—XAxisProps | YAxisPropsAll Recharts XAxis / YAxis props are accepted
| Name | Type | Default | Description |
|---|---|---|---|
tick | object | { style: { fontSize, fill } } | Axis label style — applies design tokens by default (--font-size-2xs, --color-text-subtle). Override with a custom object |
width (YAxis) | number | "auto" | "auto" | Y-axis width — "auto" adjusts to data. Pass a number for fixed width |
...props | XAxisProps | YAxisProps | — | All Recharts XAxis / YAxis props are accepted |
Anatomy
Best Practices
Do
- ✓Centralize labels and colors via ChartConfig
- ✓Always enable accessibilityLayer
- ✓Set container size with min-h or aspect-video
- ✓Use design token colors
Don't
- ✗Don't use hardcoded color values directly
- ✗Don't place a chart without a container size
- ✗Don't pack more than 5 series into one chart
- ✗Don't force data comparison without a grid
Accessibility
Keyboard
ARIA / WCAG
accessibilityLayerkeyboard and screen reader support- Tooltip provides data values as text
- Legend identifies series
- Color tokens automatically support dark mode