Skip to content

GaugeChart

One number on a scale that is known in advance, drawn as a dial. It reads from further away than a bar of the same value, which is what suits it to a dashboard tile.

tsx
import { GaugeChart } from 'neba';

<GaugeChart label="Memory" caption="Memory" value={82} />;

Props

PropTypeDefaultDescription
value * number | nullThe reading. null draws the dial with nothing on it
minnumber0The bottom of the range
maxnumber100The top of the range
sweepnumber180How far round the dial goes, in degrees, opened symmetrically about twelve o clock. 180 is a half-dial, 270 the instrument shape, 360 a ring
thicknessnumber0.22How thick the arc is, as a fraction of its radius
thresholdsreadonly NebaThreshold[]Where the arc changes colour: the same { from, color } entries a Meter takes, with the same rule
ticksnumber | falsefalseHow many marks are drawn around the dial, ends included. Off by default: a gauge on a dashboard is read as a proportion
showRangebooleantrueWrites min and max at the two ends of the arc
centerReactNodeWhat goes in the middle. Left out, it is the value written through format
captionReactNodeA line under the value: the unit, or what is being measured
colorshared'primary' | 'secondary' | 'success' | 'warning' | 'danger' | 'info''primary'The family the arc carries before any threshold is reached
heightnumber | stringHow tall the drawing is. Defaults to the size ladder
formatIntl.NumberFormatOptionsHow the numbers are written
labelstringThe accessible name. Given one, the dial is one role="img"
emptyReactNodeWhat to draw when there is nothing to draw

Every Box prop passes through, so the dial can be a card of its own. There is no legend and no tooltip: one value has nothing to distinguish and nothing to uncover. The number is written in the middle.

It is a Meter bent into an arc, and deliberately the same component in two shapes: value, min, max and thresholds mean what they mean there, so a reading can move from a bar to a dial without changing what it says.

It is not a PieChart with shape="semi". A pie is parts of a whole and every slice is a category; this is one value against a scale, and the unfilled part of the arc is not a second category: it is the rest of the dial.

Examples

value · min · max

value of null draws the dial with nothing on it and a dash in the middle.

thresholds

Where the arc changes colour. The last entry the value has reached wins; below all of them color stands.

sweep

How far round the dial goes, opened symmetrically about twelve o'clock. 180 is the half-dial a tile wants, 270 is the instrument shape, 360 is a ring. The drawing is sized against the box for the sweep it was given, so a half-dial does not leave an empty half above it.

ticks · thickness · showRange

ticks draws marks around the dial, ends included; it is off by default, because a gauge on a dashboard is read as a proportion and ticks are for an instrument somebody takes a number off. thickness is the arc's weight as a fraction of its radius, and showRange writes min and max at the two ends.

center · caption

The value in the middle is real text: selectable, findable, and in the accessibility tree. center replaces it, for the dial whose reading is a word; caption is a line under it for the unit.

Accessibility

  • Given a label, the dial is one role="img" named with the reading and the top of its range. Without one it is a plain box, and the number in the middle is read as the text it already is.
  • Colour is never the only carrier: a reading that has crossed a threshold has also filled more of the arc, and the number is written out.

Released under the MIT License