Linear gauge
Since 0.1.0-alpha.23Use a linear gauge for one reading on a known scale, such as a temperature or a tank's level. A length reads more exactly than a dial's angle, in less space. Against a target with ranges, use a bullet graph. For history, use a line chart.
Bands
Give LinearGauge a Value and a Label. The scale runs from Min to Max, 0 to 1 by default, with round ticks; ValueFormat formats the value and the ticks. Each GaugeBand marks a range on the track, and a value in it colors the bar.
Static
Preview
Code
@* A standby generator's tanks, in liters. Under a quarter of a tank is low and under a tenth
critical: the bar takes the color of the band it's in, and the band's name shows beside the value. *@
<Stack Gap="6" Grow>
foreach (var tank in _tanks)
{
<LinearGauge Label="tank.Name" Value="tank.Liters" Max="tank.Capacity" ValueFormat="#,##0 L"
Palette="ChartPalette.Of(Color.Danger, Color.Warning)">
<GaugeBand From="0" To="tank.Capacity * 0.1" Label="Critical" />
<GaugeBand From="tank.Capacity * 0.1" To="tank.Capacity * 0.25" Label="Low" />
</LinearGauge>
}
</Stack>
{
private readonly (string Name, double Liters, double Capacity)[] _tanks =
[
("Diesel, main tank", 3_150, 5_000),
("Diesel, day tank", 210, 1_000),
("Coolant reserve", 34, 200),
];
}Add this example to a page with the izzy CLI:
izzy add component LinearGauge --at <file>:<line>Palette colors the bands in order; without it they're grays, darkest first, and the bar keeps the primary color. A band's Label shows beside the value, so the color isn't the only cue.
The gauge is as wide as its container.
Marker and ticks
For a reading that isn't an amount, set Pointer="LinearGaugePointer.Marker": a triangle points at the value in place of a bar from the start. Step sets the numbered ticks, and MinorStep adds shorter ones between them.
Static
Preview
Code
@* Sea-level pressure at a weather station. A reading isn't an amount, so a marker points at it in
place of a bar from the scale's start. The bands are the usual reading, in the default grays. *@
<LinearGauge Label="Pressure" Value="1004" Min="960" Max="1060" Step="20" MinorStep="5" ValueFormat="0 hPa"
Pointer="LinearGaugePointer.Marker">
<GaugeBand From="960" To="1000" Label="Low" />
<GaugeBand From="1000" To="1025" Label="Normal" />
<GaugeBand From="1025" To="1060" Label="High" />
</LinearGauge>Target marks a goal with a tick across the track. Reversed runs the scale the other way. HideScale leaves out the ticks and their numbers, for a gauge small enough for a table cell.
Needle and ticks inside
When the bands are the reading, set Pointer="LinearGaugePointer.Needle". TickPlacement="TickPlacement.Inside" draws the ticks over the bands.
Static
Preview
Code
@* A day's meals against the dietary guidelines' ranges for each share of calories (US Dietary
Guidelines: carbohydrate 45–65%, fat 20–35%, protein 10–35%). Below, within and above each range
are tints of one color up to the color itself; the needle reads where the day fell. *@
<Stack Gap="8" Grow>
foreach (var (label, share, low, high, palette) in _intake)
{
<LinearGauge Label="label" Value="share" ValueFormat="P0" Step="0.1" MinorStep="0.02"
Pointer="LinearGaugePointer.Needle" TickPlacement="TickPlacement.Inside"
Palette="palette">
<GaugeBand From="0" To="low" Label="Below range" />
<GaugeBand From="low" To="high" Label="In range" />
<GaugeBand From="high" To="1" Label="Above range" />
</LinearGauge>
}
</Stack>
{
private readonly (string Label, double Share, double Low, double High, ChartPalette Palette)[] _intake =
[
("Fat", 0.40, 0.20, 0.35, ChartPalette.Tints(Color.Warning)),
("Carbohydrate", 0.35, 0.45, 0.65, ChartPalette.Tints(Color.Success)),
("Protein", 0.25, 0.10, 0.35, ChartPalette.Tints(Color.Info)),
];
}ChartPalette.Tints colors the bands from a light tint up to the full color, with no black mixed in, so a large area stays clear; Shades, which darkens toward black, suits a chart's series better.
The needle takes the gauge's Accent, or the text color. The band's label names where the value falls.
ScaleSide="ScaleSide.Start" puts the numbers above the scale, and the inside ticks hang from the top edge.
Vertical, with pointers
To stand the scale up, low at the bottom, set Orientation="Orientation.Vertical". It's 12rem tall; Height sets another.
Static
Preview
Code
@* The same station's temperature, standing up like a thermometer, with the dew point on the same
scale; and its relative humidity, with the comfortable range between the bands. *@
<Row Gap="12" Wrap Justify="Justify.Center">
<LinearGauge Label="Temperature" Value="24" Min="-10" Max="40" Step="10" MinorStep="2" ValueFormat="0°C"
Orientation="Orientation.Vertical">
<GaugePointer Value="12" Label="Dew point" />
</LinearGauge>
<LinearGauge Label="Humidity" Value="0.47" ValueFormat="P0" Step="0.25" Orientation="Orientation.Vertical">
<GaugeBand From="0" To="0.3" Label="Dry" />
<GaugeBand From="0.6" To="1" Label="Humid" />
</LinearGauge>
</Row>A GaugePointer is another value on the same scale, written under the gauge as "Dew point 12°C". Each pointer is a meter of its own, named by its label.
Details
Pointer sets the bar (the default) or a triangle. The label and value are written above the scale. As wide as its container across; 12rem tall standing up (Height).
Bands are grays, darkest first, unless Palette or a band's Accent colors them; a value in a colored band takes its color, and its label shows beside the value. Target marks a goal with a tick across the track. Each GaugePointer is another value on the same scale, a triangle in its color, written under the scale: "Dew point 12°". With HideLabel and HideScale, a bar and a target tick small enough for a table cell.
Parts
Written inside LinearGauge. The API page lists their parameters.
GaugeBand: a range on aGauge's dial or aLinearGauge's scale, such as where a load turns high:<GaugeBand From="0.7" To="0.9" Accent="Accent.From(Color.Warning)" Label="High" />.GaugePointer: another value on aGaugeorLinearGauge, on the same scale, such as the dew point beside the temperature:<GaugePointer Value="12" Label="Dew point" />.
Mode support
| Feature | Static | Interactive |
|---|---|---|
| A bar from the scale's start, a marker at the value, or a needle into the bands | Yes | Yes |
| Bands along the track that color the value and name its range | Yes | Yes |
| Round ticks by default, or your own step, with minor ticks, beside the track or over it | Yes | Yes |
| Across or standing up, either way round | Yes | Yes |
| A target tick, and more values as pointers | Yes | Yes |
| Read as a meter, with its value in words | Yes | Yes |
Static: static server-side rendering, with no circuit and no WebAssembly. Interactive: Server, WebAssembly or Auto.
Accessibility
- role="meter" on the scale, named by
Label, which is required, with aria-valuenow, -min and -max, and the formatted value as aria-valuetext with its band's label and the target, so a screen reader hears "Pressure, 1004 hPa, Normal". - Colors aren't read: a band's
Labelsays what its color means, on screen and to screen readers. - Each
GaugePointeris a meter of its own, named by its label, after the gauge's.
Parameters
| Prop | Type | Default |
|---|---|---|
PointerHow the value is drawn: LinearGaugePointer.Bar (the default), a bar beside the track from Min; LinearGaugePointer.Marker, a triangle at the value, for a reading that isn't an amount, such as air pressure; or LinearGaugePointer.Needle, a needle into a thick track, where the bands are the gauge. | LinearGaugePointer | LinearGaugePointer.Bar |
TickPlacementWhere the ticks are drawn: TickPlacement.Outside the track (the default), or TickPlacement.Inside, over it, which thickens the track to hold them. | TickPlacement | TickPlacement.Outside |
ScaleSideWhich side the numbers are on: ScaleSide.Start, above across and left standing up, or ScaleSide.End, below across and right standing up. | ScaleSide? | computed |
OrientationOrientation.Horizontal (the default) runs the scale across, the label above it; Orientation.Vertical stands it up, low at the bottom, like a thermometer. | Orientation | Orientation.Horizontal |
HeightStanding up, the scale's height. | Length? | computed |
ReversedRuns the scale the other way: from the right across, from the top standing up. | bool | false |
StepThe step between numbered ticks, such as 20. | double? | computed |
MinorStepThe step between shorter ticks with no number, such as 5. | double? | |
HideScaleLeaves out the ticks and their numbers, for a gauge small enough for a table cell. | bool | false |
RefreshHow often the gauge reads its data again, at least a second, such as Refresh="TimeSpan.FromSeconds(30)". | TimeSpan? | |
RefreshFromOn a static page with Refresh: a lighter page to fetch than this one, which renders the same gauge with the same id. | string? | |
ValueThe value. | double | Required |
MinThe scale's start. | double | 0 |
MaxThe scale's end. | double | 1 |
LabelWhat it measures, such as "Disk used": written with the value, and its accessible name. | string | Required |
HideLabelHides the label, which still names the gauge for screen readers. | bool | false |
ValueFormatA .NET format string for the value, the scale's numbers, the target and the pointers, such as P0, N0 or 0 mb. | string? | |
TargetA goal to read the value against, such as 0.8: a tick across the track, read with the value. | double? | |
AccentThe value's color, such as Accent.Of("#0d9488"). | Accent? | computed |
PaletteThe bands' colors, in the order they're written, such as ChartPalette.Of(Color.Warning, Color.Danger), or ChartPalette.Tints(Color.Warning) for a light tint up to the full color (for a thick track's bands). | ChartPalette? | computed |
ChildContentThe GaugeBands, ranges along the scale such as where a load turns high, and GaugePointers, more values on the same scale. | RenderFragment? | |
OnRefreshOn an interactive page with Refresh: raised at each interval, to load new data. | EventCallback |
Plus 17 item props and 4 common props.
Full APISee also
- Gauge: shows one value against its range, such as progress toward a goal.
- Progress: shows a progress bar, with or without a known value.
- BulletChart: shows measures against their targets and ranges, a row each, such as a KPI scorecard.