Basic Line

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.

sample image sample image

View model

namespace ViewModelsSamples.Lines.Basic;

public class ViewModel
{
    public double[] Values1 { get; set; } =
        [2, 1, 3, 5, 3, 4, 6];

    public int[] Values2 { get; set; } =
        [4, 2, 5, 2, 4, 5, 3];
}

XAML

<UserControl
    x:Class="WPFSample.Lines.Basic.View"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.WPF;assembly=LiveChartsCore.SkiaSharpView.WPF"
    xmlns:vms="clr-namespace:ViewModelsSamples.Lines.Basic;assembly=ViewModelsSamples"
    xmlns:draw="clr-namespace:LiveChartsCore.SkiaSharpView.Drawing.Geometries;assembly=LiveChartsCore.SkiaSharpView"
    xmlns:local="clr-namespace:WPFSample.Lines.Basic">

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

    <lvc:CartesianChart>
        <lvc:CartesianChart.Title>
            <lvc:XamlDrawnLabelVisual
                Text="My chart title"
                Paint="#303030"
                TextSize="25"
                Padding="15"/>
        </lvc:CartesianChart.Title>

        <lvc:CartesianChart.Series>
            <lvc:SeriesCollection>
                <lvc:XamlLineSeries
                    Values="{Binding Values1}"
                    Fill="{x:Null}"
                    GeometrySize="20"/>
                <local:CustomStarLineSeries
                    Values="{Binding Values2}"
                    Fill="{x:Null}"
                    GeometrySize="20"/>
            </lvc:SeriesCollection>
        </lvc:CartesianChart.Series>
    </lvc:CartesianChart>

</UserControl>

CustomGeometryPointColumnSeries.cs

using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.WPF;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;

namespace WPFSample.Lines.Basic;

// WPF xaml parser does not support generic types
// we instead create a non-generic class that inherits from the generic one.
public class CustomStarLineSeries : XamlLineSeries<int, StarGeometry> { }

Articles you might also find useful: