Skip to content
ChartslibraryUI
Get Pro

React gauge chart

One number on a half-circle scale against a fixed limit, with an optional target.

FreeMIT · install in one command<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.

When to use

  • Quota or plan attainment
  • Budget used against the full budget
  • Capacity or utilisation with a fixed maximum

When not to use

  • You need the trend, not just today's value – use KPI tile
  • Several numbers side by side – use Bullet chart
  • There is no natural maximum – use KPI tile

Good practice

  • Only use it when the scale has a real end (100% of quota, the full budget).
  • Say what the number is in caption.
  • Pair it with a trend elsewhere on the page.

Installation

Gauge chart is free under the MIT license.

pnpm dlx shadcn@latest add https://chartslibraryui.com/r/gauge-chart.json

Installs 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

Usage

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"
    />
  );
}

Data

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

Props

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;
}

Source

Installs gauge-chart.tsx and the shared core/ (12 files).

View gauge-chart.tsx
"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>
  );
}

KPI tile

A headline number with its comparison, direction-aware colour and an optional sparkline.

Pro

Bullet chart

KPIs against targets and qualitative ranges: the compact replacement for gauges.

Pro

Pacing chart

Cumulative month-to-date actual against plan with a run-rate projection.

Sign in to ChartslibraryUI

New here? The same step creates your account.

Continue with Google
or

No password needed. Bought Pro? Use the email you paid with and your license is there. By signing in you agree to the Terms and Privacy policy.