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="AvaloniaSample.Pies.Gauge5.View"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
    xmlns:vms="using:ViewModelsSamples.Pies.Gauge5"
    x:DataType="vms:ViewModel">

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

    <Grid RowDefinitions="Auto, *">

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

        <lvc:PieChart
            Grid.Row="1"
            InitialRotation="-90"
            MinValue="0"
            MaxValue="100"
            MaxAngle="270"
            LegendPosition="Bottom">

            <lvc:PieChart.Series>

                <lvc:XamlGaugeSeries
                    SeriesName="North"
                    GaugeValue="{Binding Value1}"
                    DataLabelsPosition="Start"/>

                <lvc:XamlGaugeSeries
                    SeriesName="South"
                    GaugeValue="{Binding Value2}"
                    DataLabelsPosition="Start"/>

            </lvc:PieChart.Series>

        </lvc:PieChart>
    </Grid>
</UserControl>

Articles you might also find useful: