Line Geometries

The [ObservableObject], [ObservableProperty] and [RelayCommand] attributes come from the CommunityToolkit.Mvvm package, you can read more about it here.

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

sample image

View model

using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore;
using LiveChartsCore.Drawing;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;

namespace ViewModelsSamples.Lines.Custom;

public partial class ViewModel : ObservableObject
{
    public ISeries[] Series { get; set; } =
    {
        new LineSeries<double>
        {
            Values = new double[] { 2, 1, 4, 2, 2, -5, -2 },
            Fill = null,
            GeometrySize = 20
        },

        // use the second type parameter to specify the geometry to draw for every point
        // there are already many predefined geometries in the
        // LiveChartsCore.SkiaSharpView.Drawing.Geometries namespace
        new LineSeries<double, RectangleGeometry>
        {
            Values = new double[] { 3, 3, -3, -2, -4, -3, -1 },
            Fill = null,
            GeometrySize = 20
        },

        // You can also use SVG paths to draw the geometry
        // LiveCharts already provides some predefined paths in the SVGPoints class.
        new LineSeries<double, SVGPathGeometry>
        {
            Values = new double[] { -2, 2, 1, 3, -1, 4, 3 },
            Fill = null,
            GeometrySvg = SVGPoints.Star,
            GeometrySize = 20
        },

        // you can declare your own gemetry and use the SkiaSharp api to draw it
        new LineSeries<double, MyGeometry>
        {
            Values = new double[] { 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 xmlns="http://xamarin.com/schemas/2014/forms"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             x:Class="XamarinSample.Lines.Custom.View"
             xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Xamarin.Forms;assembly=LiveChartsCore.SkiaSharpView.XamarinForms"
             xmlns:vms="clr-namespace:ViewModelsSamples.Lines.Custom;assembly=ViewModelsSamples">
    <ContentPage.BindingContext>
        <vms:ViewModel/>
    </ContentPage.BindingContext>
    <lvc:CartesianChart Series="{Binding Series}"/>
</ContentPage>

Articles you might also find useful:

Cartesian chart control
Line series properties