Skip to content
Playground

Chart

Zenos design-system helpers around Recharts primitives.

Zenos design-system helpers around Recharts primitives.

Powered by Recharts for chart geometry and rendering. Zenos owns configuration metadata, semantic variables, tooltip and legend presentation, and container behavior.

pnpm dlx @zentara-co/zenos-cli add chart

The command installs Recharts and adds the chart helpers to the consumer project. Import Zenos helpers from the installed recipe and geometry primitives from Recharts:

TSX
import { Bar, BarChart, CartesianGrid, XAxis } from "recharts";import {  ChartContainer,  ChartTooltip,  ChartTooltipContent,  type ChartConfig,} from "./components/chart";

Recharts owns geometry and rendering. Zenos owns ChartContainer, ChartConfig, ChartTooltip, ChartTooltipContent, ChartLegend, ChartLegendContent, semantic series variables, and design-system presentation.

Use bars when readers need to compare discrete categories or time buckets. Keep the zero baseline visible when magnitude is the primary comparison.

TSX
import { Bar, BarChart, CartesianGrid, XAxis } from "recharts";import {  ChartContainer,  ChartTooltip,  ChartTooltipContent,  type ChartConfig,} from "./components/chart"; const config = {  revenue: { label: "Revenue", color: "var(--chart-1)" },} satisfies ChartConfig; <ChartContainer config={config} aria-label="Monthly revenue">  <BarChart data={data}>    <CartesianGrid vertical={false} />    <XAxis dataKey="month" />    <ChartTooltip content={<ChartTooltipContent />} />    <Bar dataKey="revenue" fill="var(--color-revenue)" />  </BarChart></ChartContainer>;

Stacked bars show a total and its composition at the same time. Use them when the combined height matters and the segments share the same unit.

Give related Bar elements the same stackId. The example keeps the successful and breached portions in one column, adds a legend, and uses a line indicator in the tooltip. Prefer grouped bars when readers need precise side-by-side comparisons between segments.

Use lines for trends across an ordered dimension. This sentiment example follows the same structure as a production analytics chart: three related series, dashed horizontal and vertical grid lines, quiet axes, visible data points, and a larger active point.

The legend and tooltip both read labels and colors from the same ChartConfig, so Positive, Neutral, and Negative stay synchronized across the visualization and interaction content.

Area charts emphasize magnitude over time. The filled variant reuses the sentiment data and adds an independent vertical gradient beneath each series. The fill fades to transparent so overlapping values, grid lines, and tooltip cursor remain readable.

Define gradients inside the chart SVG and reference scoped --color-{key} variables. This keeps the presentation theme-aware without reading the active theme in application code.

Use a donut for a small part-to-whole dataset. The center summary should show the total by default and the active segment value during pointer exploration.

The example groups smaller publishers into “Others,” dims inactive sectors on hover, updates the center label through a polite live region, and keeps the legend outside the SVG so long labels can truncate predictably. For more than five or six categories, prefer a sorted bar chart.

Radar charts compare several dimensions that share a meaningful scale. They work best for a small profile such as current posture against a target, not for ranking unrelated values.

Keep every axis on the same domain, limit the number of dimensions, and distinguish overlapping polygons with both stroke style and fill opacity. Include a legend because the shapes overlap.

Use a radial bar for a single bounded value when the compact visual is more useful than a standard progress bar. Always repeat the exact value as text.

The visible 76% is the primary value; the arc is supporting context. Set the radius axis domain explicitly so the chart represents the full 0–100 range.

  • Use bars for comparison across categories and stacked bars for composition within a total.
  • Use lines for change over an ordered interval and areas when magnitude is also important.
  • Use a donut only for a short part-to-whole breakdown.
  • Use radar for a compact multidimensional profile with a shared scale.
  • Use radial progress for one bounded metric. Use the Progress component when space, precision, or familiarity matters more than visual emphasis.

Keep data shaping outside the chart markup. Convert timestamps, group small categories, calculate percentages, and supply fallback zeroes before rendering. Each row should have a stable category key and numeric values for every visible series.

For asynchronous data, render loading, empty, and error states around ChartContainer. Do not render an empty SVG as the only explanation. A useful empty state names the missing dataset and, when possible, the filter or date range that produced it.

The recipe uses --chart-1 through --chart-5, plus grid, axis, and tooltip roles. The CLI only inserts missing tokens.

Each config key should match a Recharts dataKey. ChartContainer maps its color to a scoped --color-{key} variable:

TSX
const config = {  organic: { label: "Organic", color: "var(--chart-1)" },  referral: { label: "Referral", color: "var(--chart-2)" },} satisfies ChartConfig;

Use the scoped variables inside series so the same component responds to theme tokens without branching on the active theme.

ChartTooltipContent supports dot, line, and dashed indicators. Use valueFormatter for units, currency, percentages, or domain-specific formatting. Use labelFormatter when the axis label needs a readable date or period.

ChartLegendContent resolves the same labels and optional icons from ChartConfig. Set hideIcon only when series names remain distinguishable without a color marker.

Remove axis and tick lines when the grid already establishes the scale. Use tickMargin to separate labels from the plot and reserve enough YAxis width for the longest formatted value. Dashed grids suit dense analytical views; fewer or horizontal-only lines keep simple comparison charts quieter.

Format dates and compact numbers at the axis boundary, but preserve exact values in the tooltip or a nearby data table.

ChartContainer uses a responsive Recharts container and defaults to a video aspect ratio. Override its height or aspect ratio at the composition site:

TSX
<ChartContainer config={config} className="h-72 aspect-auto" aria-label="Monthly revenue">  <BarChart data={data}>{/* ... */}</BarChart></ChartContainer>

Give a chart an explicit height when it sits inside a grid or resizable panel. Avoid relying on percentage height when no ancestor establishes a height.

Keep animation brief and avoid replaying it after every hover or parent render. Disable nonessential animation for frequently updating dashboards and respect the user’s reduced-motion preference. For large datasets, reduce the number of visible points, aggregate by an appropriate interval, and avoid expensive custom SVG renderers on every mark.

Test the information and interaction contract rather than Recharts internals. Assert the chart’s accessible name, legend labels, formatted tooltip values, filters, and any live summaries. Avoid depending on generated SVG path data or element order, which can change between rendering-engine versions.

  • Add aria-label or aria-labelledby to ChartContainer.
  • Enable Recharts accessibilityLayer for keyboard-readable Cartesian and polar charts.
  • Provide a nearby text summary or data table when exact values are essential.
  • Do not encode meaning with color alone; use labels, legends, line styles, or direct annotations.
  • Announce changing center summaries only when the interaction communicates useful information.
  • Respect reduced motion when adding series or number animations.

Use Recharts directly for axes, grids, series, reference geometry, and interaction callbacks. The recipe intentionally does not hide those capabilities behind a large chart prop API.

PropTypeDefaultDescription
config ChartConfig — Series labels, colors, icons, and semantic metadata.
children ReactElement — A Recharts chart primitive.
content ReactElement — Custom content supplied to ChartTooltip or ChartLegend.
hideLabel / hideIndicator boolean false Tooltip density controls.
indicator 'dot' | 'line' | 'dashed' dot Tooltip series marker.
nameKey / labelKey string — Metadata lookup keys.