Custom Bars

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 UserControl instance, but LiveCharts controls can be used inside any container.

sample image

View model

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

namespace ViewModelsSamples.Bars.Custom;

public class ViewModel
{
    public ISeries[] Series { get; set; } = [
        new ColumnSeries<double> ([2, 1, 4]),

        // 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 ColumnSeries<double, DiamondGeometry>([4, 3, 6]),

        // You can also use SVG paths to draw the geometry
        // the VariableSVGPathGeometry can change the drawn path at runtime
        new ColumnSeries<double, VariableSVGPathGeometry>([-2, 2, 1])
        {
            GeometrySvg = SVGPoints.Star
        },

        // finally you can also use SkiaSharp to draw your own geometry
        new ColumnSeries<double, MyGeometry>([4, 5, 2])
    ];
}

MyGeometry.cs

using LiveChartsCore.SkiaSharpView.Drawing;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using SkiaSharp;

namespace ViewModelsSamples.Bars.Custom;

public class MyGeometry : SizedGeometry
{
    public override void OnDraw(SkiaSharpDrawingContext context, SKPaint paint)
    {
        var canvas = context.Canvas;
        var y = Y;

        while (y < Y + Height)
        {
            canvas.DrawLine(X, y, X + Width, y, paint);
            y += 5;
        }
    }
}

XAML

<UserControl x:Class="WPFSample.Bars.Custom.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.Bars.Custom;assembly=ViewModelsSamples">
    <UserControl.DataContext>
        <vms:ViewModel/>
    </UserControl.DataContext>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <lvc:CartesianChart Series="{Binding Series}"></lvc:CartesianChart>
    </Grid>
</UserControl>

Articles you might also find useful:

Cartesian chart control
Column series properties