Layered Bars

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

using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;

namespace ViewModelsSamples.Bars.Layered;

public class ViewModel
{
    public int[] Values1 { get; set; } =
        [6, 3, 5, 7, 3, 4, 6, 3];

    public int[] Values2 { get; set; } =
        [2, 4, 8, 9, 5, 2, 4, 7];
}

XAML

<UserControl
    x:Class="AvaloniaSample.Bars.Layered.View"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
    xmlns:vms="using:ViewModelsSamples.Bars.Layered"
    x:DataType="vms:ViewModel">

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

    <!--
      When the bar positon is ignored, all bars are drawn in the same position.
    -->

    <lvc:CartesianChart>
        <lvc:CartesianChart.Series>
            <lvc:XamlColumnSeries
                Values="{Binding Values1}"
                MaxBarWidth="999999"
                IgnoresBarPosition="True"/>
            <lvc:XamlColumnSeries
                Values="{Binding Values2}"
                MaxBarWidth="30"
                IgnoresBarPosition="True"/>
        </lvc:CartesianChart.Series>
    </lvc:CartesianChart>

</UserControl>

Articles you might also find useful: