Skip to content
Focsd homeFocsd homeFocsd
Forms

Gauge

One value on a dial, with optional named bands such as Normal, Warning and Critical.

  • Tag: focsd-gauge
  • Pattern: Meter (role=meter) with named bands
  • Category: Charts

Example

HTML
<div class="stack">
<focsd-gauge
id="gauge-demo"
label="CPU load"
value="72"
format="unit percent"
show-value></focsd-gauge>
</div>
<script type="module">
// The bands are data, so they are set from script.
document.getElementById('gauge-demo').bands = [
{ to: 60, label: 'Normal', tone: 'positive' },
{ to: 85, label: 'Warning', tone: 'caution' },
{ to: 100, label: 'Critical', tone: 'critical' },
];
</script>

Usage

Import the module once, then use the tag like any HTML element. Every framework below renders the same element; see Frameworks for setup.

<script type="module">
import '@focsd-dev/charts';
</script>
<focsd-gauge label="CPU load" value="72" format="unit percent" show-value></focsd-gauge>

API

Attributes

AttributePropertyTypeDefault
valuevaluenumber0
minminnumber0
maxmaxnumber100
labellabelstring—
formatformatIntl.NumberFormatOptions | undefined—
show-valueshowValuebooleanfalse

CSS parts

Style the inside of the component with ::part(), for example focsd-gauge::part(gauge).

PartDescription
gaugeThe wrapper.
arcThe filled part of the dial, up to the value.
trackThe whole dial behind it.
bandEach band on the outer ring.
tickThe mark between two bands.
needleThe pointer.
valueThe value as text, shown with `show-value`.
labelThe label under the dial.
legendThe list of bands.

Accessibility

  • A meter named by its label, with aria-valuemin, aria-valuemax and aria-valuenow. The value text includes the current band, such as "72%, Warning", so no meaning is carried by color.
  • The bands are also a visible list ("Normal, up to 60%"), with the current band marked, so the dial is not the only way to read them.
  • The value is kept inside min and max; a max that is not above min falls back to min + 1. A missing label warns once in the console.
  • There is no animation. Forced colors draw every shape in the system text color.