Radial Gradients

sample image sample image

Hover over the image to see the chart animation

This sample uses C# 12 features, it also uses features from the CommunityToolkit.Mvvm package, you can learn more about it here.

View Model

using SkiaSharp;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;

namespace ViewModelsSamples.Design.RadialGradients;

public class ViewModel
{
    // radial gradients are based on SkiaSharp circular gradients
    // for more info please see:
    // https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/graphics/skiasharp/effects/shaders/circular-gradients

    private static readonly SKColor[] s_colors = [
        new SKColor(179, 229, 252),
        new SKColor(1, 87, 155)
        // ...

        // you can add as many colors as you require to build the gradient
        // by default all the distance between each color is equal
        // use the colorPos parameter in the constructor of the RadialGradientPaint class
        // to specify the distance between each color
    ];

    public ISeries[] Series { get; set; } = [
        new PieSeries<int>
        {
            Name = "Maria",
            Values = [7],
            Stroke = null,
            Fill = new RadialGradientPaint(s_colors),
            Pushout = 10,
            OuterRadiusOffset = 20
        },
        new PieSeries<int>
        {
            Name = "Charles",
            Values = [3],
            Stroke = null,
            Fill = new RadialGradientPaint(new SKColor(255, 205, 210), new SKColor(183, 28, 28))
        }
    ];
}

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.Design.RadialGradients.View"
             xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Xamarin.Forms;assembly=LiveChartsCore.SkiaSharpView.XamarinForms"
             xmlns:vms="clr-namespace:ViewModelsSamples.Design.RadialGradients;assembly=ViewModelsSamples">
    <ContentPage.BindingContext>
        <vms:ViewModel/>
    </ContentPage.BindingContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <lvc:PieChart Series="{Binding Series}" LegendPosition="Right"></lvc:PieChart>
    </Grid>
</ContentPage>