UI Toolbox logoUI Toolbox
Support

Gauge

A Gauge is a dial. It shows a value on a 270 degree scale with an arc or a needle.

Three dials: speed with colored bands, a boost needle and a health arcThree dials: speed with colored bands, a boost needle and a health arc

Video tutorial: Gauge. All videos: Video tutorials.

<UIToolbox.Gauge max-value="200" value="60" format-string="0' km/h'">
    <UIToolbox.GaugeRange from="140" to="170" color="#FFBF33" />
    <UIToolbox.GaugeRange from="170" to="200" color="#E64033" />
</UIToolbox.Gauge>
<UIToolbox.Gauge
    display-mode="Needle"
    min-value="-40"
    max-value="60"
    divisions="4"
    thickness="4" />

Set the bands in UXML or in the Range Bands list of the UI Builder Inspector. Then the code sets only the value:

speed.Value = car.Speed;

The same bands in C#:

speed.Ranges = new[]
{
    new GaugeRange(140, 170, new Color(1f, .75f, .2f)),
    new GaugeRange(170, 200, new Color(.9f, .25f, .2f)),
};
Member Description
MinValue (min-value), MaxValue (max-value) The scale (0 to 100). A minimum above the maximum moves the maximum up, and the reverse.
Value (value) The value, kept on the scale. A NaN scale or value is ignored, so a binding to a number that is not ready yet does not break the dial. The round end of the arc ends on the value, so it lines up with the range bands.
DisplayMode (display-mode) A GaugeDisplay: Arc (default) fills from the start of the scale. Needle points at the value.
Animate (animate) Eases the arc or needle to a new value in about 0.25 s (on). The value text always changes at once.
Thickness (thickness) The width of the arc in pixels (8).
Divisions (divisions) The steps between the major ticks (5). The scale has one more major tick than divisions. 0 hides the ticks.
MinorTicks (minor-ticks) The minor ticks between two major ticks (4).
ShowLabels (show-labels) Shows the value of each major tick (on).
ShowValue (show-value) Shows the value below the center (on).
FormatString (format-string), TickFormat (tick-format) The .NET formats of the value text and the tick labels ("0"). Quote literal text: 0' km/h'. The Inspector has a list of common formats and a sample.
Ranges (GaugeRange children) Colored bands on the rim, each with From (from), To (to) and Color (color). In UI Builder, add them in the Range Bands list of the Inspector. Set Ranges again after a change to a band. The arc or needle takes the color of the last range that holds the value. GaugeRange.Contains(value) tells whether a band holds a value.
UseRangeColor (use-range-color) The arc or needle takes the color of the range that holds the value (on). Off, it keeps the USS color, and the ranges are only bands on the rim.

No data

A gauge has a value at all times, so it shows "No data" when you say so: set NoData while the reading is missing, such as a sensor that is offline. The value arc or needle and the value text hide, the track and the ticks stay as the placeholder, and a centered pill shows the text "No data".

<tb:Gauge value="62" no-data="true" />
<tb:Gauge no-data="true" no-data-text="Offline" />
Member Description
NoDataText (no-data-text) The text of the pill. Empty (the default) shows the translated "No data" (the ToolboxText key tb.no-data, in nine languages), which follows a language change.
ShowNoData (show-no-data) True (the default) shows the faint shape and the pill. False leaves an empty chart.
NoData (no-data) True while there is no reading. The value arc or needle and the value text hide and the pill shows. False (the default) shows the value.

In the examples

Styling

Class or property Element
tb-gauge The dial. Set its width and height for the size. color is the value color outside the ranges.
--tb-gauge-track A custom property on the dial: the track color. A transparent color draws no track.
--tb-gauge-tick A custom property on the dial: the tick color. A transparent color draws no ticks.
tb-gauge__value The value text below the center.
tb-gauge__tick-label A major tick label. The script sets left and top; keep position: absolute and translate: -50% -50%.
tb-gauge--needle On the dial in needle mode.