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


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. |
- The size comes from USS (120 px). The value uses
color, the track--tb-gauge-trackand the ticks--tb-gauge-tick. See Styling. - The gauge is a display. It has no input and no change event.
- A value that changes in each frame makes no garbage. A
Labeltakes a C# string, and a string cannot change, sovalue.ToString()in each frame makes a new string each time. The garbage collector then stops the game now and then to clear them: a hitch. AStringBuilderdoes not help, because itsToString()also makes a new string. The gauge writes the value text into characters on the stack instead, and keeps one string for each text that it shows. A gauge from 0 to 240 km/h makes each of its texts once, the first time it shows them, and after that it reuses them. To show your own numbers the same way, make the strings once at the start and pick one by index, asGaugeDemo.unitydoes for its status line.
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. |
- A gauge is empty while
NoDatais on, whatever itsValueis. Turn it off when the reading comes back. - The pill hides as soon as data arrives, and shows again when the data goes. No code runs per frame.
- The pill needs a chart of at least 72 × 36 pixels (for a graph and a Sankey chart, the plot). A smaller chart shows no pill.
- The track and the ticks are the placeholder, so the gauge draws no extra shape.
- The classes are
tb-chart-no-data(the overlay, in--tb-color-text-muted) andtb-chart-no-data__pill(the pill). Restyle them for the look of your game.
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. |