KPI tile
A headline number with its comparison, direction-aware colour and an optional sparkline.
One number on a half-circle scale against a fixed limit, with an optional target.
<GaugeChart />A gauge shows one number on a scale with a real end: quota attained, budget used, capacity in use. The filled arc is the value, the tick is the target, and the line under the number says how far above or below target you are, in words and in the right colour.
Gauges are easy to overuse. They take a lot of space for a single number and show no trend, so use one only when the limit itself matters, and put the trend next to it. For several numbers against targets, a bullet chart packs the same information into a row each.
The chart takes props rather than rows: value, min, max and an optional target. Percent formats default to a 0 to 100% scale.
Gauge chart is free under the MIT license.
pnpm dlx shadcn@latest add https://chartslibraryui.com/r/gauge-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 gauge chart for your AI tool and attach it to Claude, ChatGPT, Lovable or Cursor. No terminal needed. How it works
import { GaugeChart } from "@/components/charts/gauge-chart";
export function Example() {
return (
<GaugeChart
title="Q4 quota is 82% closed with three weeks to go"
subtitle="Bookings as a share of Q4 quota"
value={0.82}
target={0.9}
format="percent"
caption="of Q4 quota"
/>
);
}
Props, not rows: value, min, max and an optional target.
<GaugeChart value={0.82} target={0.9} format="percent" caption="of Q4 quota" />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 GaugeChartProps extends FrameProps {
/** The current value. */
value: number | null;
/** Start of the scale. Default 0. */
min?: number;
/** End of the scale. Default 100, or 1 for percent formats. */
max?: number;
/** Optional target, drawn as a tick on the arc and compared in the caption. */
target?: number;
/** What the number is, shown under it, e.g. "of quarterly quota". */
caption?: string;
/** Number format: "currency", "percent", "integer", "compact" or a format object. */
format?: FormatInput;
/** Which direction is good, for colouring the gap to target. Default "up". */
favorable?: Favorable;
}Installs gauge-chart.tsx and the shared core/ (12 files).
"use client";
import { color as tokens, toneOf, toneText, type Favorable } from "./core/color";
import { isNum, type Issue } from "./core/data";
import { formatDelta, formatValue, tickFormatter, type FormatInput } from "./core/format";
import { ChartFrame, type FrameProps } from "./core/frame";
import { arcPath } from "./core/path";
import { useWords } from "./core/words";
export interface GaugeChartProps extends FrameProps {
/** The current value. */
value: number | null;
/** Start of the scale. Default 0. */
min?: number;
/** End of the scale. Default 100, or 1 for percent formats. */
max?: number;
/** Optional target, drawn as a tick on the arc and compared in the caption. */
target?: number;
/** What the number is, shown under it, e.g. "of quarterly quota". */
caption?: string;
/** Number format: "currency", "percent", "integer", "compact" or a format object. */
format?: FormatInput;
/** Which direction is good, for colouring the gap to target. Default "up". */
favorable?: Favorable;
}
/**
* One number on a half-circle scale, with an optional target. Use it for progress toward a fixed limit
* (quota, budget used, capacity). For trends or several numbers, use KPI tiles or bars.
*/
export function GaugeChart({ value, min = 0, max: maxProp, target, caption, format, favorable = "up", height: hProp, ...frame }: GaugeChartProps) {
const L = useWords(frame.words);
const isPct = format === "percent" || (typeof format === "object" && format !== null && "kind" in format && format.kind === "percent");
const max = maxProp ?? (isPct ? 1 : 100);
const issues: Issue[] = [];
if (!isNum(value)) issues.push({ level: "error", message: "No value to display." });
else if (max <= min) issues.push({ level: "error", message: "max must be greater than min." });
else if (value < min || value > max) issues.push({ level: "note", message: `The value ${formatValue(value, format)} is outside the scale and is drawn at the end.` });
const height = hProp ?? 210;
const share = isNum(value) && max > min ? Math.max(0, Math.min(1, (value - min) / (max - min))) : 0;
const gap = isNum(value) && isNum(target) ? value - target : null;
const tone = gap === null ? "neutral" : toneOf(gap, favorable);
const table = {
columns: [
{ key: "k", label: "Measure" },
{ key: "v", label: L.value, align: "right" as const, format: (v: unknown) => formatValue(v as number, format, { context: "table" }) },
],
rows: [{ k: L.value, v: value }, { k: L.min, v: min }, { k: L.max, v: max }, ...(isNum(target) ? [{ k: L.target, v: target }] : [])],
};
const summary = `Gauge: ${formatValue(value, format)} on a scale from ${formatValue(min, format)} to ${formatValue(max, format)}${isNum(target) ? `, target ${formatValue(target, format)}` : ""}.`;
return (
<ChartFrame {...frame} height={height} issues={issues} table={table} summary={summary}>
{({ width }) => {
const r = Math.max(40, Math.min(width / 2 - 12, height - 50));
const inner = r * 0.74;
const cx = width / 2;
const cy = r + 10;
const a = (s: number) => -Math.PI / 2 + s * Math.PI;
const tShare = isNum(target) && max > min ? Math.max(0, Math.min(1, (target - min) / (max - min))) : null;
const tick = (s: number, r0: number, r1: number) => {
const ang = a(s);
return { x1: cx + r0 * Math.sin(ang), y1: cy - r0 * Math.cos(ang), x2: cx + r1 * Math.sin(ang), y2: cy - r1 * Math.cos(ang) };
};
return (
<svg width={width} height={height} role="img" aria-label={summary}>
<path d={arcPath(cx, cy, inner, r, a(0), a(1))} style={{ fill: "var(--clui-grid)" }} />
{share > 0 && <path d={arcPath(cx, cy, inner, r, a(0), a(share))} style={{ fill: tokens.series(0) }} />}
{tShare !== null && <line {...tick(tShare, inner - 6, r + 6)} style={{ stroke: "var(--clui-ink)" }} strokeWidth={2} strokeLinecap="round" />}
<text x={cx} y={cy - 6} textAnchor="middle" className="clui-kpi-value" style={{ fontSize: Math.max(22, Math.min(40, r * 0.36)), fontWeight: 600, fill: "var(--clui-ink)" }}>
{formatValue(value, format)}
</text>
{caption && (
<text x={cx} y={cy + 14} textAnchor="middle" className="clui-label" style={{ fill: "var(--clui-ink-2)" }}>
{caption}
</text>
)}
<text x={cx - (r + inner) / 2} y={cy + 16} textAnchor="middle" className="clui-tick">
{tickFormatter(format, [min, max])(min)}
</text>
<text x={cx + (r + inner) / 2} y={cy + 16} textAnchor="middle" className="clui-tick">
{tickFormatter(format, [min, max])(max)}
</text>
{isNum(target) && (
<text x={cx} y={cy + 34} textAnchor="middle" className="clui-label" style={{ fill: toneText(tone), fontWeight: 500 }}>
{gap === null ? "" : gap === 0 ? "On target" : `${formatDelta(Math.abs(gap), format).replace(/^[+−-]/, "")} ${gap > 0 ? "above" : "below"} target of ${formatValue(target, format)}`}
</text>
)}
</svg>
);
}}
</ChartFrame>
);
}
A headline number with its comparison, direction-aware colour and an optional sparkline.
KPIs against targets and qualitative ranges: the compact replacement for gauges.
Cumulative month-to-date actual against plan with a run-rate projection.