Gauges

A gauge is a PieChart that shows one or more values against a fixed range, set by the MinValue and MaxValue of the chart. A solid gauge fills an arc up to each value. An angular gauge draws colored sections, ticks and a needle that points at the value. Gauge series are pie series, so they take every property described in the Pie charts article; this article covers only what is specific to gauges.

This article highlights the most used features. Every property is listed in the API explorer: GaugeGenerator, GaugeItem, PieSeries, NeedleVisual and AngularTicksVisual. In XAML, declare them as XamlGaugeSeries, XamlGaugeBackgroundSeries, XamlAngularGaugeSeries, XamlNeedle and XamlAngularTicks.

Basic gauge

Set the MinValue and MaxValue of the chart to the range of the gauge. Then add a XamlGaugeSeries and set its GaugeValue. When MaxValue is not set, the chart uses the sum of the values, as a regular pie chart does, and the gauge is always full.

The default theme places the value at the center of the chart (DataLabelsPosition is ChartCenter) and rounds the ends of the arc with a CornerRadius of 8. InitialRotation is the angle where the arc starts, in degrees: 0 is the right side of the chart and the angles grow clockwise, so -90 starts at the top. MaxRadialColumnWidth limits the width of the arc in pixels; the arc stays at the outer edge of the chart.

Gauge: A single value on a ring.

Angles

MaxAngle is the angle the whole range covers, 360 by default. This sample draws a 270 degree gauge: it starts at -225, the bottom left, and ends at the bottom right, leaving the gap at the bottom. Set IsClockwise to false to fill the arc in the other direction.

270 degrees gauge: A gauge that opens at the bottom.

Background

The background series draws the whole arc, from MinValue to MaxValue, behind the values. It is not shown in the legend, and the default theme fills it with a light gray (a light transparent white in the dark theme). Add a XamlGaugeBackgroundSeries to the chart to draw it, and give it the same InnerRadius as the gauge series so the rings match:

<lvc:XamlGaugeBackgroundSeries
    InnerRadius="75"
    Fill="{lvc:SolidColorPaint Color='#5A64B5F6'}"/>

Leave it out, or set its Fill to {x:Null}, to draw the gauge without a background.

Multiple values

Add one XamlGaugeSeries per value. Each value gets its own ring: the first one is the inner ring. InnerRadius leaves a hole in the center, and RelativeInnerRadius and RelativeOuterRadius leave space between the rings. The background draws behind every ring.

Here the labels go at the Start of each arc, and the DataLabelsFormatter adds the series name to the value.

Multiple values gauge: One ring per value.

Slim gauges

A small MaxRadialColumnWidth draws each value as a thin line. This sample sets it to 5, places the labels at the End of each arc, and hides the background by setting its Fill to null.

Slim gauge: Thin rings over a light track.

Updating the value

Bind GaugeValue to a property that notifies its changes, and the gauge animates to the new value.

Gauge updates: Gauges that animate to new values.

See automatic updates for more.

Angular gauge

An angular gauge has three parts:

  • Sections: one XamlAngularGaugeSeries per section. All the sections share one ring and are placed one after another, in order, starting at MinValue: each value is the length of its section, not its end. In this sample the sections 60, 30 and 10 cover 0 to 60, 60 to 90 and 90 to 100. Sections have no data labels, do not react to the pointer and do not animate. OuterRadiusOffset makes the ring smaller to leave room for the ticks.
  • Ticks: a XamlAngularTicks draws an arc with ticks and labels along the range. The step between ticks is about a tenth of the range, rounded up to 1, 2 or 5 times a power of ten, with four smaller ticks between two labels. OuterOffset moves the arc and the ticks in from the edge of the chart, LabelsOuterOffset does the same for the labels, TicksLength is the length of the ticks, LabelsSize the size of the labels (12 by default) and Labeler formats them.
  • Needle: a XamlNeedle points at its Value. Width is 20 in the default theme, and Fill paints it. Change Value to move it.

The ticks and the needle are visual elements, so they go in the VisualElements of the chart. Both use the MinValue, MaxValue, InitialRotation and MaxAngle of the chart, so set them, and both only work in a PieChart.

Angular gauge: A needle over colored sections.

Add a XamlGaugeBackgroundSeries to draw a background behind the sections. The default theme rounds gauge slices with a CornerRadius of 8; this sample sets it to 0 so the sections join with square ends.

Custom needle

The needle is drawn by a NeedleGeometry. Inherit from it to change the needle, then use your class as the type argument of the visual: NeedleVisual<SmallNeedle>. XamlNeedle always draws the default needle, so create the visual in your view model and bind the VisualElements of the chart to a collection that contains it.

This needle sets a ScaleTransform of 0.6, so it is 40% smaller than the default one:

public class SmallNeedle : NeedleGeometry
{
    public SmallNeedle()
    {
        ScaleTransform = new(0.6f, 0.6f);
    }
}
var needle = new NeedleVisual<SmallNeedle> { Value = 45 };

Override Draw() to draw the needle yourself with SkiaSharp. X and Y are the center of the chart, Radius the length of the needle and Width its width; the visual rotates the geometry to the value. This one draws a rectangle:

public class CustomNeedle : NeedleGeometry
{
    public override void Draw(SkiaSharpDrawingContext context)
    {
        var paint = context.ActiveSkiaPaint;

        context.Canvas.DrawRect(X - Width * 0.5f, Y, Width, Radius, paint);
    }
}

custom needle

The default NeedleGeometry source is a good starting point.

~/piechart/gauges.md