Gauge
One value on a dial, with optional named bands such as Normal, Warning and Critical.
Example
<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>import { useEffect, useRef } from 'react';import '@focsd-dev/charts';
export function Example() { const ref = useRef(null); return <focsd-gauge ref={ref} label="CPU load" value="72" format="unit percent" show-value></focsd-gauge>;}<script setup>import '@focsd-dev/charts';</script>
<template> <focsd-gauge label="CPU load" value="72" format="unit percent" show-value></focsd-gauge></template>// Add CUSTOM_ELEMENTS_SCHEMA to the component's schemas, then:import '@focsd-dev/charts';
// template<focsd-gauge label="CPU load" value="72" format="unit percent" show-value></focsd-gauge><script> import '@focsd-dev/charts';</script>
<focsd-gauge label="CPU load" value="72" format="unit percent" show-value></focsd-gauge>API
Attributes
| Attribute | Property | Type | Default |
|---|---|---|---|
value | value | number | 0 |
min | min | number | 0 |
max | max | number | 100 |
label | label | string | — |
format | format | Intl.NumberFormatOptions | undefined | — |
show-value | showValue | boolean | false |
CSS parts
Style the inside of the component with ::part(), for example focsd-gauge::part(gauge).
| Part | Description |
|---|---|
gauge | The wrapper. |
arc | The filled part of the dial, up to the value. |
track | The whole dial behind it. |
band | Each band on the outer ring. |
tick | The mark between two bands. |
needle | The pointer. |
value | The value as text, shown with `show-value`. |
label | The label under the dial. |
legend | The list of bands. |
Accessibility
- A
meternamed by itslabel, witharia-valuemin,aria-valuemaxandaria-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
minandmax; amaxthat is not aboveminfalls back tomin + 1. A missinglabelwarns once in the console. - There is no animation. Forced colors draw every shape in the system text color.
Ask the docs
Hi, what are you building?
Ask about any component, theming, forms or frameworks. I answer with the right component, a snippet and a link to its docs.