Line Geometries
This sample uses C# 12 features, it also uses features from the CommunityToolkit.Mvvm package, you can learn more about it here.
This web site wraps every sample using a ContentPage
instance, but LiveCharts controls can be used inside any container.

View model
using LiveChartsCore;
using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
namespace ViewModelsSamples.Lines.Custom;
public class ViewModel
{
public ISeries[] Series { get; set; } =
[
new LineSeries<double>
{
Values = [2, 1, 4, 2, 2, -5, -2],
Fill = null,
GeometrySize = 20
},
// use the second generic parameter to define the geometry to draw
// there are many predefined geometries in the LiveChartsCore.Drawing namespace
// for example, the StarGeometry, CrossGeometry, RectangleGeometry and DiamondGeometry
new LineSeries<double, StarGeometry>
{
Values = [3, 3, -3, -2, -4, -3, -1],
Fill = null,
GeometrySize = 20
},
// You can also use SVG paths to draw the geometry
// the VariableSVGPathGeometry can change the drawn path at runtime
new LineSeries<double, VariableSVGPathGeometry>
{
Values = [-2, 2, 1, 3, -1, 4, 3],
Fill = null,
GeometrySvg = SVGPoints.Pin,
GeometrySize = 20
},
// finally you can also use SkiaSharp to draw your own geometry
new LineSeries<double, MyGeometry>
{
Values = [4, 5, 2, 4, 3, 2, 1],
Fill = null,
GeometrySize = 20
},
];
}
MyGeometry.cs
using LiveChartsCore.SkiaSharpView.Drawing;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using SkiaSharp;
namespace ViewModelsSamples.Lines.Custom;
public class MyGeometry : SizedGeometry
{
public override void OnDraw(SkiaSharpDrawingContext context, SKPaint paint)
{
var canvas = context.Canvas;
canvas.DrawRect(X, Y, Width, Height, paint);
canvas.DrawLine(X, Y, X + Width, Y + Height, paint);
canvas.DrawLine(X + Width, Y, X, Y + Height, paint);
}
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="MauiSample.Lines.Custom.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.Lines.Custom;assembly=ViewModelsSamples">
<ContentPage.BindingContext>
<vms:ViewModel/>
</ContentPage.BindingContext>
<lvc:CartesianChart Series="{Binding Series}"/>
</ContentPage>