Basic Pie

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.

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

sample image

View model

namespace ViewModelsSamples.Pies.Basic;

public class PieData(string name, double value)
{
    public string Name { get; set; } = name;
    public double[] Values { get; set; } = [value];
}

public class ViewModel
{
    public PieData[] Data { get; set; } = [
            new("Mary", 10),
            new("John", 20),
            new("Alice", 30),
            new("Bob", 40),
            new("Charlie", 50)
        ];
}

XAML

<UserControl
    x:Class="WinUISample.Pies.Basic.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.Basic"
    mc:Ignorable="d">

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

    <lvc:PieChart SeriesSource="{Binding Data}">
        <lvc:PieChart.SeriesTemplate>
            <DataTemplate>
                <lvc:XamlPieSeries
                    SeriesName="{Binding Name}"
                    Values="{Binding Values}"/>
            </DataTemplate>
        </lvc:PieChart.SeriesTemplate>
        <lvc:PieChart.Title>
            <lvc:XamlDrawnLabelVisual
                Text="My chart title"
                Paint="{lvc:SolidColorPaint Color='#000'}"
                TextSize="{lvc:Float Value='25'}"
                Padding="{lvc:Padding Value='15'}"/>
        </lvc:PieChart.Title>
    </lvc:PieChart>

</UserControl>

Articles you might also find useful: