Skip to documentation content

Gauge Chart

Show one value on a fixed scale, with optional ranges that say whether it is good or bad.

Basic Chart

Overview

A gauge shows a single value on a scale with a known minimum and maximum, such as a score, a utilisation percentage, or progress toward a target. Bands mark the ranges that matter, so readers see at once whether the value is normal or needs attention. A gauge takes a lot of space for one number: use a stat with a Radial Chart ring for several progress values, or a line chart when the trend matters more than the current reading.

Anatomy

GaugeChart owns the value, scale, and loading state. Arc sets the sweep (semi, three-quarter arc, or full) and thickness. Bands draws colored ranges in a thin outer ring and, by default, colors the value with the range it falls in. Ticks marks the scale, Needle adds a pointer, Center prints the value as HTML in the middle, and Legend names the bands.

Accessibility

The plot is exposed as a meter with aria-valuemin, aria-valuemax, aria-valuenow, and a value text that includes the band name, so assistive technology reads the value directly. The band colors are paired with a band name in the center caption and the legend. Pass ariaLabel to give the meter a more specific name.

Installation

npm install honestui

Usage

import { GaugeChart, type ChartConfig } from "honestui/charts";
const chartConfig = {
  target: { label: "of monthly target", colors: { light: ["#3b82f6"], dark: ["#60a5fa"] } },
} satisfies ChartConfig;
<GaugeChart value={72} max={100} dataKey="target" config={chartConfig}>
  <GaugeChart.Arc type="semi" thickness={16} />
  <GaugeChart.Center valueFormatter={(value) => `${value}%`} />
</GaugeChart>

dataKey names the config entry that labels and colors the value. Values outside min and max are clamped on the arc; the center still prints the real value. A new value eases from the previous one rather than redrawing from the minimum.

Examples

Bands and ticks

<Bands /> <Ticks />

Needle

<Needle />

Loading state

isLoading

API reference

GaugeChart
PropTypeDefaultDescription
value*number | null–The current value. null draws the empty track and an em dash.
dataKey*string–The config key that labels and colors the value.
config*ChartConfig–Labels and colors for the value and bands. See Chart Config.
minnumber0Start of the scale.
maxnumber100End of the scale.
isLoadingbooleanfalseShows the loading track.
animationbooleantruePlays the sweep and value easing. Reduced motion turns them off.
ariaLabelstring–Accessible name for the meter.
chartOptionsRecord<string, unknown>–Escape hatch merged over the ECharts option.
Arc
PropTypeDefaultDescription
typesemi|arc|full"semi"A half circle, a three-quarter arc, or a full ring.
thicknessnumber12Arc width in pixels.
roundCapbooleantrueRounds the arc ends.
trackbooleantrueDraws the muted track behind the value.
Bands
PropTypeDefaultDescription
bands*{ to: number; dataKey: string }[]–Ranges in order; each ends at to and takes its config entry.
thicknessnumber3Band ring width in pixels.
colorProgressbooleantrueColors the value with its band.
Ticks
PropTypeDefaultDescription
countnumber5Number of scale divisions.
showLabelsbooleantruePrints the tick values.
formatter(value: number) => string–Formats tick values.
Needle
PropTypeDefaultDescription
lengthnumber | string"72%"Needle length, in pixels or a percentage of the radius.
Center
PropTypeDefaultDescription
valueReactNode–Replaces the printed value.
labelReactNode–The caption. Defaults to the active band's label, or the dataKey label.
valueFormatter(value: number) => string–Formats the value.
classNamestring–Classes for the readout.
Legend
PropTypeDefaultDescription
variantLegendVariant"rounded-square"Indicator style.
alignleft|center|right"center"Horizontal placement.
verticalAligntop|bottom"bottom"Vertical placement.