Angular Gauge
The [ObservableObject]
, [ObservableProperty]
and [RelayCommand]
attributes come from the
CommunityToolkit.Mvvm package, you can read more about it
here.

View model
using System.Collections.Generic;
using LiveChartsCore;
using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Extensions;
using LiveChartsCore.VisualElements;
using LiveChartsCore.SkiaSharpView.Drawing;
using LiveChartsCore.SkiaSharpView.VisualElements;
using LiveChartsCore.Defaults;
using CommunityToolkit.Mvvm.Input;
using System;
namespace ViewModelsSamples.Pies.AngularGauge;
public partial class ViewModel : ObservableObject
{
private readonly Random _random = new();
public ViewModel()
{
var sectionsOuter = 130;
var sectionsWidth = 20;
Needle = new NeedleVisual
{
Value = 45
};
Series = GaugeGenerator.BuildAngularGaugeSections(
new GaugeItem(60, s => SetStyle(sectionsOuter, sectionsWidth, s)),
new GaugeItem(30, s => SetStyle(sectionsOuter, sectionsWidth, s)),
new GaugeItem(10, s => SetStyle(sectionsOuter, sectionsWidth, s)));
VisualElements = new VisualElement<SkiaSharpDrawingContext>[]
{
new AngularTicksVisual
{
LabelsSize = 16,
LabelsOuterOffset = 15,
OuterOffset = 65,
TicksLength = 20
},
Needle
};
}
public IEnumerable<ISeries> Series { get; set; }
public IEnumerable<VisualElement<SkiaSharpDrawingContext>> VisualElements { get; set; }
public NeedleVisual Needle { get; set; }
[RelayCommand]
public void DoRandomChange()
{
// modifying the Value property updates and animates the chart automatically
Needle.Value = _random.Next(0, 100);
}
private static void SetStyle(
double sectionsOuter, double sectionsWidth, PieSeries<ObservableValue> series)
{
series.OuterRadiusOffset = sectionsOuter;
series.MaxRadialColumnWidth = sectionsWidth;
}
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="XamarinSample.Pies.AngularGauge.View"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Xamarin.Forms;assembly=LiveChartsCore.SkiaSharpView.XamarinForms"
xmlns:vms="clr-namespace:ViewModelsSamples.Pies.AngularGauge;assembly=ViewModelsSamples">
<ContentPage.BindingContext>
<vms:ViewModel/>
</ContentPage.BindingContext>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="50"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Button Grid.Row="0" Command="{Binding DoRandomChangeCommand}">Change Value</Button>
<lvc:PieChart
Grid.Row="1"
Series="{Binding Series}"
VisualElements="{Binding VisualElements}"
InitialRotation="-225"
MaxAngle="270"
MinValue="0"
Total="100">
</lvc:PieChart>
</Grid>
</ContentPage>