Custom

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

using System;
using LiveChartsCore.Kernel;

namespace ViewModelsSamples.Pies.Custom;

public class PieData(string name, double value, double offset)
{
    public string Name { get; set; } = name;
    public double[] Values { get; set; } = [value];
    public double Offset { get; set; } = offset;
    public Func<ChartPoint, string> Formatter { get; set; } =
        point =>
        {
            var pv = point.Coordinate.PrimaryValue;
            var sv = point.StackedValue!;

            return $"{pv}/{sv.Total}{Environment.NewLine}{sv.Share:P2}";
        };
}

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

XAML

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

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

    <lvc:PieChart
        InitialRotation="-90"
        SeriesSource="{Binding Data}">
        <lvc:PieChart.SeriesTemplate>
            <DataTemplate>
                <lvc:XamlPieSeries
                    SeriesName="{Binding Name}"
                    Values="{Binding Values}"
                    OuterRadiusOffset="{Binding Offset}"
                    ShowDataLabels="True"
                    ToolTipLabelFormatter="{Binding Formatter}"
                    DataLabelsFormatter="{Binding Formatter}"/>
            </DataTemplate>
        </lvc:PieChart.SeriesTemplate>
    </lvc:PieChart>

</UserControl>

Articles you might also find useful: