Basic Pie

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

This web site wraps every sample using a UserControl instance, but LiveCharts controls can be used inside any container.

sample image

View model

using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using CommunityToolkit.Mvvm.ComponentModel;

namespace ViewModelsSamples.Pies.Basic;

[ObservableObject]
public partial class ViewModel
{
    public ViewModel()
    {
        Series = new ISeries[]
        {
            new PieSeries<double> { Values = new double[] { 2 }, Name = "Slice 1" },
            new PieSeries<double> { Values = new double[] { 4 }, Name = "Slice 2" },
            new PieSeries<double> { Values = new double[] { 1 }, Name = "Slice 3" },
            new PieSeries<double> { Values = new double[] { 4 }, Name = "Slice 4" },
            new PieSeries<double> { Values = new double[] { 3 }, Name = "Slice 5" }
        };

        // the next code is equivalent to the previous one, // mark
        // but using the AsLiveChartsPieSeries() extension.

        // you could convert any IEnumerable to a pie series collection
        // so it is easier to convert an array or collection of data to a pie chart.

        //var data = new List<double> { 2, 4, 1, 4, 3 };
        //Series = data.AsLiveChartsPieSeries();

        // and the name property? try this: // mark
        //Series = data.AsLiveChartsPieSeries((value, series) =>
        //{
        //    // here you can configure the series assigned to each value.
        //    series.Name = $"Series for value {value}";
        //});
    }

    public ISeries[] Series { get; set; }
}

XAML


<UserControl x:Class="AvaloniaSample.Pies.Basic.View"
             xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:lv="clr-namespace:LiveChartsCore;assembly=LiveChartsCore"
             xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
             xmlns:vms="using:ViewModelsSamples.Pies.Basic">
  <UserControl.DataContext>
    <vms:ViewModel/>
  </UserControl.DataContext>
  <lvc:PieChart Series="{Binding Series}" LegendPosition="Right"/>
</UserControl>

Articles you might also find useful: