MDK Logo

GaugeChart

GaugeChart - Presentational gauge / speedometer chart. Implementation note: this component used to wrap the `react-gauge-chart` NPM package, but that package…

GaugeChart - Presentational gauge / speedometer chart.

Implementation note: this component used to wrap the react-gauge-chart NPM package, but that package is published only as CommonJS with a broken module field that points at the same CJS file. That made it crash under ESM bundlers that don't add a __esModule ? .default : module interop shim (Webpack 4, raw esbuild, certain SSR setups, etc.) with React's "Element type is invalid" error. We replaced it with a pure-SVG internal implementation (see ./gauge-svg.tsx) so the component is bundler- and runtime-agnostic and has zero third-party runtime dependencies.

import { GaugeChart } from "@tetherto/mdk-react-devkit";
PropStatusTypeDefaultDescription
percentRequirednumberValue between 0 and 1 (e.g. 0.75 = 75%). Values outside the range are clamped.
colorsOptionalstring[] | undefinedArc colours in HEX format.
arcWidthOptionalnumber | undefinedArc thickness as a fraction of the gauge radius (0–1).
nrOfLevelsOptionalnumber | undefinedNumber of arc segments. Ignored when `arcsLength` is provided.
arcsLengthOptionalnumber[] | undefinedCustom arc-segment proportions (auto-normalised), overriding `nrOfLevels`. e.g. `[0.7, 0.3]` for a progress-style gauge whose first arc is the fill.
needleColorOptionalstring | undefinedNeedle + hub colour.
hideNeedleOptionalboolean | undefinedHide the needle + hub (e.g. for a progress-style gauge).
formatTextValueOptional((percent: number) => string) | undefinedFormat the centre label from the clamped fraction (0–1).
hideTextOptionalboolean | undefinedHide the percentage text rendered inside the gauge.
idOptionalstring | undefinedStable id used for the gauge's accessibility labels.
heightOptionalstring | number | undefinedChart height in pixels or any CSS length (e.g. `'200px'` or `'50%'`).
maxWidthOptionalnumber | undefinedMaximum width in pixels.
classNameOptionalstring | undefined

Usage

A gauge / speedometer chart drawn as pure inline SVG (no third-party runtime dependency). Accepts a percent value between 0 and 1 and displays it as a coloured arc.

Notes

  • percent is automatically clamped to [0, 1].
  • When rendering multiple gauges on the same page, provide a unique id for each instance so their SVG accessibility labels stay distinct.
  • For a progress-style gauge (single fill arc, no needle) pass arcsLength={[percent, 1 - percent]} with two colors and hideNeedle.

Example

/** * Runnable example for GaugeChart. */import { GaugeChart } from '@tetherto/mdk-react-devkit'export const GaugeChartExample = () => (  <div className="mdk-example-row">    <GaugeChart percent={0.72} id="gauge-hash-rate" />    <GaugeChart      percent={0.45}      id="gauge-efficiency"      colors={['#34C759', '#FF9500', '#FF3B30']}      nrOfLevels={5}    />    <GaugeChart percent={0.95} id="gauge-uptime" hideText height={160} />    <GaugeChart      percent={0.68}      id="gauge-progress"      arcsLength={[0.68, 0.32]}      colors={['#009393', '#00939330']}      hideNeedle      formatTextValue={(p) => `${Math.round(p * 100)}%`}    />  </div>)