Skip to content
GitHub

Chart

Visualize data with beautiful charts.

For more complete, copy-ready setups (bar, line, area, pie, radar, tooltips, and more):

Browse the Charts Examples (soon).

Installation

Component

These pieces follow the familiar shadcn/ui chart pattern—container, tooltips, and legend helpers around standard Recharts charts—restyled and wired to Shark UI tokens and imports so the result feels native to this kit.

Usage

Walk through a small bar chart: sample data, a shared config object, then layers for grid, axis, tooltip, and legend.

Start with data

Shape the rows however you like; dataKey maps columns to bars, lines, or areas. This set tracks desktop versus mobile counts per month:

Add a chart config

ChartConfig is metadata: human-readable labels, optional icons, and color tokens. It stays separate from the data array so several charts can reuse the same palette and copy.

Render the chart

Pass config into ChartContainer. Give the container a minimum height (for example min-h-[200px]) or a fixed height so Recharts can measure the SVG responsively.

Add a grid

Import CartesianGrid from Recharts and nest it inside the chart. Horizontal stripes alone often read cleaner than a full mesh:

Add an axis

Use XAxis (and YAxis when you need one) for categories and ticks. Here ticks are shortened and decorative lines are hidden for a lighter look:

Add a tooltip

Shark’s tooltip pair reads names, swatches, and values from chartConfig automatically:

Add a legend

ChartLegend with ChartLegendContent mirrors the same config entries:

Chart config

Treat ChartConfig as the presentation contract for your series keys: labels for tooltips and legends, optional Lucide (or other) icons, and either a single color string or a theme map for light and dark. Data arrays stay focused on numbers and categories.

Because config is independent of rows, you can fetch remote data in one shape while keeping stable color tokens in code, share one config across a dashboard, or swap palettes without touching API responses.

Use color for a single value that works in both themes, or theme with light / dark keys when the swatch should diverge.

Theming

You can theme series with CSS variables (ideal alongside Shark’s tokens), raw color strings in any supported format, or a mix.

CSS variables

Shark’s default theme already defines --chart-1 through --chart-5 in globals.css; see Styling for how those slots fit the rest of the design system. Point config entries at those variables so charts track global palette tweaks:

Hex, HSL, or OKLCH

Inline literals work when you do not need shared tokens:

Applying colors in markup and data

The container exposes var(--color-<key>) for each config key. Use that placeholder anywhere Recharts or Tailwind can read a color:

  • Series elements: <Bar dataKey="desktop" fill="var(--color-desktop)" />
  • Data-driven fills: { browser: "chrome", visitors: 275, fill: "var(--color-chrome)" } with matching config keys
  • Tailwind utilities: <LabelList className="fill-[--color-desktop]" />

Tooltip

Pair ChartTooltip with ChartTooltipContent to get a styled surface that pulls series colors and labels from chartConfig. Pass tooltip state from Recharts by using a render function for content and spreading those props into ChartTooltipContent. Toggle the label row or the color chip with props, and switch the indicator shape between dot, line, and dashed styles.

Tooltip props

Custom label and name keys

When the tooltip should read from different fields than the default mapping, pass labelKey and nameKey so the header and each row title resolve correctly:

Legend

ChartLegend delegates rendering to ChartLegendContent, which builds items from the same config metadata as the tooltip.

Custom name key

When legend entries should track a field on each datum (for example browser), set nameKey:

Accessibility

Recharts’ accessibilityLayer opt-in wires keyboard traversal and screen-reader semantics into the chart canvas. Turn it on for interactive or data-critical views; leave it off for purely decorative thumbnails if you need to avoid extra focus targets.


For every prop on primitives such as Bar, Line, or XAxis, refer to the Recharts API reference.