Grouped bar chart
Two to four measures side by side per category.
A profile of several measures on one scale, for one to three items.
<RadarChart />A radar chart, also called a spider chart, puts several measures on spokes around a centre and joins each item's values into a shape. It's good at one thing: showing a profile, such as strong on speed and support but weak on price, and how two or three options differ in shape.
It's weaker at exact comparison, because people judge lengths along different angles poorly. This chart keeps it honest: every spoke uses the same scale, missing values are drawn as hollow dots at the centre and listed in a note, and it draws no more than three items. The exact values are always in the tooltip and table view.
For precise comparison across items, use a grouped bar chart. For more than three items, use small multiples.
Radar chart is free under the MIT license.
pnpm dlx shadcn@latest add https://chartslibraryui.com/r/radar-chart.jsonInstalls the chart, its dependencies and the shared core into your components folder.
Then import the theme once: import "@/components/charts/core/charts.css" Installation guide
Building with an AI tool? Download the radar chart for your AI tool and attach it to Claude, ChatGPT, Lovable or Cursor. No terminal needed. How it works
import { RadarChart } from "@/components/charts/radar-chart";
import { planProfile } from "./sample-data";
export function Example() {
return (
<RadarChart
title="Business wins on seats and integrations; Starter on price and setup"
subtitle="Plan scores from 0 to 10, from the 2026 pricing review"
data={planProfile}
axis="axis"
series={[
{ key: "starter", label: "Starter" },
{ key: "business", label: "Business" },
]}
max={10}
/>
);
}
One row per axis with an axis-name key and one numeric key per item.
[{ axis: "Speed", planA: 8, planB: 6 }, ...]Missing values are null. Invalid values make the chart say what’s wrong instead of drawing a misleading picture. How charts handle bad data
Every chart also accepts the shared frame props: title, subtitle, source, height, mode, toolbar. Common API
export interface RadarChartProps extends FrameProps {
/** One row per axis (spoke). See the Data section for the shape. */
data: Row[];
/** Key of the axis name in each row. */
axis: string;
/** One to three series to compare. More than three overlap and become unreadable. */
series: RadarSeries[];
/** Number format for values: "currency", "percent", "integer", "compact" or a format object. */
format?: FormatInput;
/** End of the shared scale. Default: the largest value, rounded up. Every spoke uses the same scale. */
max?: number;
}Installs radar-chart.tsx and the shared core/ (12 files).
"use client";
import { useMemo, type PointerEvent } from "react";
import { color as tokens } from "./core/color";
import { readNum, type Issue, type Row } from "./core/data";
import { formatValue, tickFormatter, type FormatInput } from "./core/format";
import { ChartFrame, ChartTooltip, localPoint, useActiveIndex, useSeriesToggle, type FrameProps, type LegendItem } from "./core/frame";
import { niceTicks } from "./core/scale";
import { truncate } from "./core/text";
export interface RadarSeries {
/** Key of the value in each row. */
key: string;
/** Name in the legend and tooltip. */
label?: string;
}
export interface RadarChartProps extends FrameProps {
/** One row per axis (spoke). See the Data section for the shape. */
data: Row[];
/** Key of the axis name in each row. */
axis: string;
/** One to three series to compare. More than three overlap and become unreadable. */
series: RadarSeries[];
/** Number format for values: "currency", "percent", "integer", "compact" or a format object. */
format?: FormatInput;
/** End of the shared scale. Default: the largest value, rounded up. Every spoke uses the same scale. */
max?: number;
}
/**
* Several measures on the same scale, for one to three items, drawn as polygons on spokes. Good for a profile
* ("strong on speed, weak on cost"); for exact comparison a grouped bar chart reads better.
*/
export function RadarChart({ data, axis, series, format, max: maxProp, height: hProp, ...frame }: RadarChartProps) {
const { axes, values, issues } = useMemo(() => {
const shown = series.slice(0, 3);
const issues: Issue[] = [];
if (!Array.isArray(data) || data.length < 3) return { axes: [] as string[], values: [] as (number | null)[][], issues: [{ level: "error", message: "A radar chart needs at least three axes (rows)." }] as Issue[] };
if (series.length > 3) issues.push({ level: "note", message: `Only the first three of ${series.length} series are drawn. Use small multiples for more.` });
let missing = 0;
const values = shown.map((s) =>
data.map((r) => {
const n = readNum(r?.[s.key]);
if (n.state === "invalid") issues.push({ level: "error", message: `"${r?.[axis]}" has a non-numeric ${s.label ?? s.key}.` });
if (n.value === null) missing++;
else if (n.value < 0) issues.push({ level: "warning", message: `Negative values are drawn at the centre ("${r?.[axis]}").` });
return n.value;
}),
);
if (missing) issues.push({ level: "note", message: `${missing} missing value(s) are drawn at the centre and marked with a hollow dot.` });
return { axes: data.map((r) => String(r?.[axis] ?? "")), values, issues };
}, [data, axis, series]);
const shown = series.slice(0, 3);
const keys = shown.map((s) => s.key);
const { hidden, toggle, focus, setFocus } = useSeriesToggle(keys);
const height = hProp ?? 340;
const top = Math.max(0, ...values.flat().filter((v): v is number => v !== null));
const ticks = niceTicks(0, maxProp ?? (top || 1), 4);
const max = maxProp ?? ticks[ticks.length - 1];
const legend: LegendItem[] = shown.map((s, i) => ({ key: s.key, label: s.label ?? s.key, color: tokens.series(i), shape: "line" }));
const f = (v: unknown) => formatValue(v as number, format, { context: "table" });
const table = {
columns: [{ key: "axis", label: axis }, ...shown.map((s) => ({ key: s.key, label: s.label ?? s.key, align: "right" as const, format: f }))],
rows: axes.map((a, j) => ({ axis: a, ...Object.fromEntries(shown.map((s, i) => [s.key, values[i]?.[j] ?? null])) })),
};
const summary = `Radar chart with ${axes.length} axes: ${axes.join(", ")}. ${shown.map((s, i) => `${s.label ?? s.key}: ${axes.map((a, j) => `${a} ${formatValue(values[i]?.[j], format)}`).join(", ")}`).join(". ")}.`;
return (
<ChartFrame {...frame} height={height} issues={issues} table={table} summary={summary} legend={shown.length > 1 ? legend : undefined} legendHidden={hidden} onLegendToggle={toggle} onLegendHover={setFocus}>
{({ width }) => <Inner {...{ width, height, axes, values, shown, hidden, focus, max, ticks: ticks.filter((t) => t <= max), format }} />}
</ChartFrame>
);
}
function Inner(p: { width: number; height: number; axes: string[]; values: (number | null)[][]; shown: RadarSeries[]; hidden: Set<string>; focus: string | null; max: number; ticks: number[]; format?: FormatInput }) {
const { width, height, axes } = p;
const { active, setActive, keyProps } = useActiveIndex(axes.length, { describe: (i) => ({ label: String(axes[i]) }) });
const cx = width / 2;
const cy = height / 2;
const r = Math.max(30, Math.min(width / 2 - 70, height / 2 - 28));
const n = axes.length;
const ang = (j: number) => (j / n) * Math.PI * 2;
const pt = (j: number, v: number | null) => {
const rr = (Math.max(0, Math.min(p.max, v ?? 0)) / (p.max || 1)) * r;
return [cx + rr * Math.sin(ang(j)), cy - rr * Math.cos(ang(j))] as const;
};
const ft = tickFormatter(p.format, p.ticks);
const onMove = (e: PointerEvent<SVGRectElement>) => {
const { x, y } = localPoint(e);
let a = Math.atan2(x - cx, cy - y);
if (a < 0) a += Math.PI * 2;
setActive(Math.round(a / ((Math.PI * 2) / n)) % n);
};
return (
<>
<svg width={width} height={height} role="group" aria-roledescription="chart" aria-label="Radar chart. Use arrow keys to read each axis." {...keyProps}>
<g className="clui-axis" aria-hidden>
{p.ticks.filter((t) => t > 0).map((t, k, all) => (
<g key={t}>
<polygon points={axes.map((_, j) => pt(j, t).join(",")).join(" ")} style={{ fill: "none", stroke: "var(--clui-grid)" }} />
{k < all.length - 1 && (
<text x={cx + 4} y={cy - (t / p.max) * r} dy="-0.2em" className="clui-tick">
{ft(t)}
</text>
)}
</g>
))}
{axes.map((a, j) => {
const [x, y] = pt(j, p.max);
const s = Math.sin(ang(j));
return (
<g key={j}>
<line x1={cx} y1={cy} x2={x} y2={y} style={{ stroke: "var(--clui-grid)" }} />
<text x={cx + (r + 10) * s} y={cy - (r + 10) * Math.cos(ang(j))} dy="0.32em" textAnchor={Math.abs(s) < 0.2 ? "middle" : s > 0 ? "start" : "end"} className="clui-tick" style={{ fill: active === j ? "var(--clui-ink)" : undefined, fontWeight: active === j ? 600 : undefined }}>
{truncate(a, 90, 11)}
</text>
</g>
);
})}
</g>
{p.shown.map((s, i) => {
if (p.hidden.has(s.key)) return null;
const dim = p.focus !== null && p.focus !== s.key;
const pts = axes.map((_, j) => pt(j, p.values[i][j]));
return (
<g key={s.key} className={`clui-mark${dim ? " clui-dim" : ""}`}>
<polygon points={pts.map((q) => q.join(",")).join(" ")} style={{ fill: tokens.series(i), fillOpacity: 0.12, stroke: tokens.series(i) }} strokeWidth={2} strokeLinejoin="round" />
{pts.map(([x, y], j) => (
<circle key={j} cx={x} cy={y} r={active === j ? 4.5 : 3} style={p.values[i][j] === null ? { fill: "var(--clui-surface)", stroke: tokens.series(i) } : { fill: tokens.series(i), stroke: "var(--clui-surface)" }} strokeWidth={1.5} />
))}
</g>
);
})}
<rect x={0} y={0} width={width} height={height} fill="transparent" onPointerMove={onMove} onPointerLeave={() => setActive(null)} />
</svg>
{active !== null && (
<ChartTooltip
x={pt(active, p.max)[0]}
y={pt(active, p.max)[1]}
width={width}
height={height}
data={{
title: axes[active],
rows: p.shown.filter((s) => !p.hidden.has(s.key)).map((s) => {
const i = p.shown.indexOf(s);
return { label: s.label ?? s.key, value: formatValue(p.values[i][active], p.format, { context: "tooltip" }), color: tokens.series(i), shape: "line" as const };
}),
}}
/>
)}
</>
);
}
Two to four measures side by side per category.
One small chart per group on a shared scale, instead of a ten-colour spaghetti chart.
Many items on one scale, optionally against a comparison, with no zero required.