Chart
Recharts charts with themed colors, a tooltip and legend that read labels from one config, and keyboard navigation with a visible focus ring.
- Data display components
- 6 parts
- 14 examples
- vs shadcn/ui
recharts
See it in a real product: Billing and Sales Overview
View blockpnpm dlx shadcn@latest add https://hextaui.com/r/chart.jsonAdds the component, the HextaUI theme tokens and any HextaUI components it depends on.
Add the theme tokens to your global CSS, if you haven’t yet.
Install the dependencies.
pnpm add recharts cnCopy and paste the following code into your project.
components/ui/chart.tsx Update the import paths to match your project setup.
You build charts with Recharts components and add the parts from chart only where you need them. Recharts is not wrapped, so its own docs and upgrade guides apply as they are.
A ChartConfig maps each data key to a label, an optional icon and a color. It stays separate from the data, so one config can serve several charts.
Give <ChartContainer /> a height, a min-h-* or an aspect-* so the chart can measure itself on the first render. Without one it falls back to aspect-video.
Each config key becomes a --color-KEY variable scoped to its chart. Point it at a theme token, at any CSS color, or give it separate light and dark values.
Use the variable wherever Recharts takes a color: on components, in your data, or in Tailwind classes.
The theme ships five chart tokens, --chart-1 to --chart-5: blue, teal, amber, violet and rose. In this order, neighbouring colors stay distinct with the common forms of color blindness, and each one has at least 3:1 contrast against the light and dark backgrounds. Use them in order and keep the legend or labels on, so color is never the only cue.
Keys that are not valid in a CSS name, such as Mobile users, become --color-Mobile-users.
A grid, an axis, <ChartTooltip /> and <ChartLegend />. The tooltip and legend read their labels and colors from the config.
indicator="line" matches the tooltip keys to the lines they describe.
Bars with the same stackId stack. Round only the outer ends, so the stack reads as one bar.
Set layout="vertical" on the chart and swap the axis types. <LabelList /> prints each value at the end of its bar.
Each slice takes its color from fill in the data. nameKey on the tooltip and legend looks up the label for each slice in the config.
Polar grids and axes pick up the same muted strokes and labels as cartesian ones.
Switch between dot, line and dashed indicators, and hide the label with hideLabel. defaultIndex on <ChartTooltip /> shows a point on the first render.
valueFormatter formats the number and keeps the indicator and name. labelFormatter does the same for the label. To replace a whole row instead, use formatter.
An icon in the config replaces the color key in the tooltip and legend.
A theme object picks a different color in each theme. Switch the site theme to see it change.
Color each bar with <Cell /> and mark zero with <ReferenceLine />.
Long series names wrap in the legend and the tooltip, and large values stay on one line beside them.
Recharts does not mirror axes on its own. Set reversed on the x-axis and move the y-axis to the right. Pass locale to the tooltip to show the reader's digits.
Recharts turns on accessibilityLayer by default, so the chart is one tab stop that you move through point by point.
| Key | Action |
|---|---|
| Tab | Focuses the chart and shows a focus ring. |
| ←→ | Moves the tooltip to the next or previous point. In a reversed axis the keys follow the screen. |
| Enter | Shows or hides the tooltip at the current point. |
- Charts are images to screen readers. Name each one with a visible title nearby or an
aria-labelon the Recharts chart, and offer a table when people need the exact values. - The tooltip and legend name every series in text, so a reader never has to match colors alone.
- With reduced motion, Recharts skips its enter animations and the tooltip jumps between points instead of gliding.
- Tooltip values are formatted in
en-USunless you passlocale, so the server and browser render the same text.
The parts sit on top of Recharts. Every Recharts prop still works on the chart components you put inside.
Provides the config, writes the color variables and renders a Recharts <ResponsiveContainer /> around its child. Takes every <div> prop.
| Prop | Type | Default |
|---|---|---|
configLabels, icons and colors for each data key. | ChartConfig | – |
childrenOne Recharts chart, such as <BarChart />. | ReactElement | – |
initialDimensionThe size used before the container is measured. | { width: number; height: number } | { width: 320, height: 200 } |
idNames the chart in data-chart. Generated when omitted. | string | – |
| Attribute | Description |
|---|---|
data-slot="chart" | The container. |
data-chart | The id the color variables are scoped to. |
--color-KEY | One color variable per configured key. |
| Prop | Type | Default |
|---|---|---|
label | ReactNode | – |
iconReplaces the color key in the tooltip and legend. | ComponentType | – |
colorAny CSS color or variable. | string | – |
themeUse instead of color for a color per theme. | { light: string; dark: string } | – |
The Recharts <Tooltip />, with a shorter glide between points. Takes every Recharts tooltip prop.
| Prop | Type | Default |
|---|---|---|
contentUsually <ChartTooltipContent />. | ReactElement | (props) => ReactNode | – |
animationDuration | number | 200 |
animationEasing | string | "ease-out" |
defaultIndexShows the tooltip at this point on first render. | number | – |
| Prop | Type | Default |
|---|---|---|
indicator | "dot" | "line" | "dashed" | "dot" |
hideLabel | boolean | false |
hideIndicator | boolean | false |
labelKeyThe config or data key to use for the label. | string | – |
nameKeyThe config or data key to use for each name. | string | – |
valueFormatterFormats each value and keeps the indicator and name. | (value, name, item) => ReactNode | – |
labelFormatter | (label, payload) => ReactNode | – |
formatterReplaces each row. | (value, name, item, index, payload) => ReactNode | – |
localeFormats numeric values. | Intl.LocalesArgument | "en-US" |
colorOne indicator color for every row. | string | – |
className | string | – |
labelClassName | string | – |
| Attribute | Description |
|---|---|
data-slot="chart-tooltip" | The box. |
data-slot="chart-tooltip-label" | The label. |
data-slot="chart-tooltip-item" | One row per series. |
data-slot="chart-tooltip-indicator" | The color key. |
data-indicator | On the key: dot, line or dashed. |
--chart-indicator | The key's color. |
The Recharts <Legend />. Takes every Recharts legend prop, and lists series in the order you declare them instead of alphabetically.
| Prop | Type | Default |
|---|---|---|
contentUsually <ChartLegendContent />. | ReactElement | (props) => ReactNode | – |
itemSorternull keeps the declared order. | "value" | "dataKey" | (item) => number | string | null | null |
| Prop | Type | Default |
|---|---|---|
hideIcon | boolean | false |
nameKeyThe config or data key to use for each name. | string | – |
className | string | – |
| Attribute | Description |
|---|---|
data-slot="chart-legend" | The list. |
data-slot="chart-legend-item" | One entry per series. |
data-slot="chart-legend-indicator" | The color swatch. |
Returns { config } inside a <ChartContainer />, for building your own tooltip or legend content.
- AvatarUser photos with an initials fallback, status badges and stacked groups that collapse into a count.
- BadgeStatus labels with colored dots, removable tags that slide closed and counts that roll to their new value.
- CardA surface for grouping content, with three variants, edge-to-edge media, concentric radii and whole-card links.
- Data tableA table for real data, with sorting, search, row selection, pinned columns, a sticky header and pagination.
- ItemA row of media, text and actions for lists, settings and pickers, with a grouped surface and a hover highlight that glides between rows.
- KbdKey caps for shortcuts that show the right symbols on every platform, read them out properly and press down with the real keys.
Used in Pro blocks
Blocks that build on Chart.
Every block comes with HextaUI Pro, and Prompt Input is free.