@biem/ui

Chart

Charts built with Recharts that take their labels and colors from one shared config.

A chart draws data with the chart components of Recharts inside ChartContainer. The container takes a config that gives every data key a label and a color, and it writes each color as a CSS variable such as --color-revenue, which the chart references in fill or stroke. ChartTooltipContent and ChartLegendContent show the labels of the config, so the tooltip and the legend use the same names as the rest of the app.

Monthly sales
Jan – Sep 2026
CHF 1'897'900 year to date

Usage

chart-default.tsx
"use client";

import { Badge } from "@biem/ui/components/ui/badge";
import {
	Card,
	CardContent,
	CardDescription,
	CardHeader,
	CardTitle,
} from "@biem/ui/components/ui/card";
import {
	type ChartConfig,
	ChartContainer,
	ChartTooltip,
	ChartTooltipContent,
} from "@biem/ui/components/ui/chart";
import {
	Bar,
	BarChart,
	CartesianGrid,
	XAxis,
	YAxis,
} from "recharts";

const monthlySales = [
	{ month: "Jan", revenue: 186400 },
	{ month: "Feb", revenue: 174800 },
	{ month: "Mar", revenue: 209600 },
	{ month: "Apr", revenue: 198200 },
	{ month: "May", revenue: 224500 },
	{ month: "Jun", revenue: 217300 },
	{ month: "Jul", revenue: 231700 },
	{ month: "Aug", revenue: 206800 },
	{ month: "Sep", revenue: 248600 },
];

const currency = new Intl.NumberFormat("de-CH", { style: "currency", currency: "CHF" });
const wholeCurrency = new Intl.NumberFormat("de-CH", { style: "currency", currency: "CHF", maximumFractionDigits: 0 });

const chartConfig = {
	revenue: { label: "Sales", color: "var(--chart-1)" },
} satisfies ChartConfig;

export function ChartDefault() {
	const yearToDate = monthlySales.reduce((total, entry) => total + entry.revenue, 0);

	return (
		<div className="w-full max-w-sm">
			<Card>
				<CardHeader>
					<div className="flex flex-wrap items-center justify-between gap-2">
						<CardTitle>Monthly sales</CardTitle>
						<Badge variant="secondary">Jan – Sep 2026</Badge>
					</div>
					<CardDescription>{wholeCurrency.format(yearToDate)} year to date</CardDescription>
				</CardHeader>
				<CardContent>
					<ChartContainer config={chartConfig} className="h-48 w-full aspect-auto" aria-label="Monthly net sales in CHF, January to September 2026">
						<BarChart accessibilityLayer data={monthlySales} margin={{ top: 8, right: 0, bottom: 0, left: 0 }}>
							<CartesianGrid vertical={false}/>
							<XAxis dataKey="month" tickLine={false} axisLine={false} tickMargin={8} interval={0} padding={{ left: 4, right: 4 }}/>
							<YAxis tickLine={false} axisLine={false} tickMargin={8} width="auto" domain={[0, (dataMax: number) => dataMax * 1.2]} tickFormatter={(value: number) => `${value / 1000}k`}/>
							<ChartTooltip cursor={false} content={<ChartTooltipContent formatter={(value) => currency.format(Number(value))}/>}/>
							<Bar dataKey="revenue" fill="var(--color-revenue)" radius={[4, 4, 0, 0]} isAnimationActive={false}/>
						</BarChart>
					</ChartContainer>
				</CardContent>
			</Card>
		</div>
	);
}

Examples

Line Chart

How a figure develops over a day, a week or a season often matters more than any single value. A line chart traces that course and lets users spot rises, peaks and turning points at a glance. With type set to "linear", every value joins the next by a straight segment, so the line never rises above or falls below the values the data contains.

Sales throughout the day
All stores · 7 October 2026, 16:00

Area Chart

Some figures describe a quantity rather than a level, such as the cases that arrive in a warehouse during a shift. Drawn with Area inside AreaChart, the course fills the space down to the axis, so users perceive the volume of each period as well as the direction in which it moves.

Receipts throughout the day
All stores · 7 October 2026, 16:00

API Reference

ChartContainer

Propconfig
TypeChartConfig
Default–
DescriptionGives every data key of the chart a label, an icon and a color. ChartContainer writes the colors as CSS variables named --color- and the key.
Propchildren
TypeReactElement
Default–
DescriptionTakes one chart of Recharts, such as BarChart or LineChart, which fills the container.
PropinitialDimension
Type{ width: number; height: number }
Default{ width: 320, height: 200 }
DescriptionSets the size of the chart before the container has measured itself.
Propid
Typestring
Default–
DescriptionSets the id that scopes the CSS variables to this chart. Without it, ChartContainer creates one.

ChartConfig

Proplabel
TypeReactNode
Default–
DescriptionNames the data key in the tooltip and the legend.
Propicon
TypeComponentType
Default–
DescriptionReplaces the color indicator of the data key in the legend.
Propcolor
Typestring
Default–
DescriptionSets one color for both themes. Takes a CSS color or a CSS variable.
Proptheme
Type{ light: string; dark: string }
Default–
DescriptionSets one color for each theme instead of color.

ChartTooltip

ChartTooltip is the Tooltip component of Recharts and takes its props. Pass ChartTooltipContent as content to show the tooltip with the labels and colors of the config.

ChartTooltipContent

Propindicator
Type"dot" | "line" | "dashed"
Default"dot"
DescriptionSets the shape that marks the color of each entry.
ProphideLabel
Typeboolean
Defaultfalse
DescriptionHides the label above the entries, such as the month of a bar.
ProphideIndicator
Typeboolean
Defaultfalse
DescriptionHides the color marks of the entries.
PropnameKey
Typestring
Default–
DescriptionSets the key that the tooltip uses to find each entry in the config, instead of its data key.
ProplabelKey
Typestring
Default–
DescriptionSets the key that the tooltip uses to find its label in the config.
Propformatter
Typefunction
Default–
DescriptionRenders the value of each entry, for example as an amount in CHF.
ProplabelFormatter
Typefunction
Default–
DescriptionRenders the label above the entries.

ChartLegend

ChartLegend is the Legend component of Recharts and takes its props. Pass ChartLegendContent as content to show the legend with the labels and colors of the config.

ChartLegendContent

ProphideIcon
Typeboolean
Defaultfalse
DescriptionShows the color mark of each entry even when the config gives it an icon.
PropnameKey
Typestring
Default–
DescriptionSets the key that the legend uses to find each entry in the config, instead of its data key.
PropverticalAlign
Type"top" | "bottom"
Default"bottom"
DescriptionReceives the position of the legend from ChartLegend and puts the space on the side of the legend that faces the chart.

ChartStyle

Propid
Typestring
Default–
DescriptionSets the chart whose CSS variables the style defines.
Propconfig
TypeChartConfig
Default–
DescriptionGives the colors that the style writes as CSS variables. ChartContainer renders ChartStyle itself, so an app only needs it for a chart outside ChartContainer.