Auto Updates On Gauges

This sample uses C# 13 preview features such as partial properties, it also uses features from the CommunityToolkit.Mvvm package, you can learn more about it here.

sample image

View model

using System;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.ComponentModel;

namespace ViewModelsSamples.Pies.Gauge5;

public partial class ViewModel : ObservableObject
{
    private readonly Random _random = new();

    [ObservableProperty]
    public partial double Value1 { get; set; } = 50;

    [ObservableProperty]
    public partial double Value2 { get; set; } = 80;

    [RelayCommand]
    public void DoRandomChange()
    {
        Value1 = _random.Next(0, 100);
        Value2 = _random.Next(0, 100);
    }
}

XAML

<UserControl x:Class="WinUISample.Pies.Gauge5.View"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
    xmlns:vms="using:ViewModelsSamples.Pies.Gauge5"
    mc:Ignorable="d"
    MaxWidth="400"
    MaxHeight="400">

    <UserControl.DataContext>
        <vms:ViewModel/>
    </UserControl.DataContext>

    <Grid RowDefinitions="Auto, *">

        <Button Grid.Row="0" Command="{Binding DoRandomChangeCommand}">Change Value</Button>

        <lvc:PieChart
            Grid.Row="1"
            InitialRotation="-90"
            MinValue="0"
            MaxValue="100"
            MaxAngle="270"
            LegendPosition="Bottom">
            <lvc:PieChart.Series>
                <lvc:SeriesCollection>
                    <!--
                    The main gauge series for North.
                    -->
                    <lvc:XamlGaugeSeries
                        SeriesName="North"
                        GaugeValue="{Binding Value1}"
                        DataLabelsPosition="Start"/>
                    <!--
                    The main gauge series for South.
                    -->
                    <lvc:XamlGaugeSeries
                        SeriesName="South"
                        GaugeValue="{Binding Value2}"
                        DataLabelsPosition="Start"/>
                </lvc:SeriesCollection>
            </lvc:PieChart.Series>
        </lvc:PieChart>
    </Grid>

</UserControl>

Articles you might also find useful: