Box Series

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.

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.Defaults;

namespace ViewModelsSamples.Box.Basic;

public class ViewModel
{
    public BoxValue[] Values1 { get; set; } =
        [
            // max, upper quartile, median, lower quartile, min
            new(100, 80, 60, 20, 70),
            new(90, 70, 50, 30, 60),
            new(80, 60, 40, 10, 50)
        ];

    public BoxValue[] Values2 { get; set; } =
        [
            new(90, 70, 50, 30, 60),
            new(80, 60, 40, 10, 50),
            new(70, 50, 30, 20, 40)
        ];

    public BoxValue[] Values3 { get; set; } =
        [
            new(80, 60, 40, 10, 50),
            new(70, 50, 30, 20, 40),
            new(60, 40, 20, 10, 30)
        ];

    public string[] Labels { get; set; } =
        ["Apperitizers", "Mains", "Desserts"];
}

XAML

<UserControl
    x:Class="AvaloniaSample.Box.Basic.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.Box.Basic"
    x:DataType="vms:ViewModel">

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

  <lvc:CartesianChart
      LegendPosition="Right">

    <lvc:CartesianChart.Series>
      <lvc:XamlBoxSeries
          SeriesName="Year 2023"
          Values="{Binding Values1}"/>
      <lvc:XamlBoxSeries
          SeriesName="Year 2024"
          Values="{Binding Values2}"/>
      <lvc:XamlBoxSeries
          SeriesName="Year 2025"
          Values="{Binding Values3}"/>
    </lvc:CartesianChart.Series>

    <lvc:CartesianChart.XAxes>
      <lvc:XamlAxis
          Labels="{Binding Labels}"
          LabelsRotation="0"
          SeparatorsPaint="{lvc:SolidColorPaint Color='#c8c8c8'}"
          SeparatorsAtCenter="False"
          TicksPaint="{lvc:SolidColorPaint Color='#232323'}"
          TicksAtCenter="True"/>
    </lvc:CartesianChart.XAxes>

  </lvc:CartesianChart>

</UserControl>

Articles you might also find useful: