Customize Visuals


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.Kernel.Events;
using LiveChartsCore.Measure;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
namespace ViewModelsSamples.General.MapPoints;
public class ViewModel
{
public ISeries[] Series { get; set; }
public ViewModel()
{
var paints = new SolidColorPaint[]
{
new(SKColors.Red),
new(SKColors.Green),
new(SKColors.Blue),
new(SKColors.Yellow)
};
var series = new ColumnSeries<int>
{
Values = [2, 5, 4, 6, 8, 3, 2, 4, 6],
DataLabelsPaint = new SolidColorPaint(new SKColor(30, 30, 30)),
DataLabelsPosition = DataLabelsPosition.Top
}
.OnPointMeasured(point =>
{
// this method is called for each point in the series
// we can customize the visual here
if (point.Visual is null) return;
// get a paint from the array
var paint = paints[point.Index % paints.Length];
// set the paint to the visual
point.Visual.Fill = paint;
});
Series = [series];
}
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="MauiSample.General.MapPoints.View"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Maui;assembly=LiveChartsCore.SkiaSharpView.Maui"
xmlns:vms="clr-namespace:ViewModelsSamples.General.MapPoints;assembly=ViewModelsSamples"
>
<ContentPage.BindingContext>
<vms:ViewModel/>
</ContentPage.BindingContext>
<ContentPage.Content>
<lvc:CartesianChart Series="{Binding Series}"></lvc:CartesianChart>
</ContentPage.Content>
</ContentPage>