Error Bars

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

sample image

View model

using System;
using LiveChartsCore.Defaults;

namespace ViewModelsSamples.Error.Basic;

public class ViewModel
{
    public ErrorValue[] Values1 { get; set; } =
        [
            // (Y, Y+- error) // mark
            new(65, 6),
            // (Y, Y+ error, Y- error) // mark
            new(70, 15, 4),
            new(35, 4),
            new(70, 6),
            new(30, 5),
            new(60, 4, 16),
            new(65, 6)
        ];

    public ErrorPoint[] Values2 { get; set; } =
        [
            // (X, Y, Y+- error, Y+- error) // mark
            new(0, 50, 0.2, 8),
            // (X, Y, X- error, X+ erorr, Y+ error, Y- error) // mark
            new(1, 45, 0.1, 0.3, 15, 4),
            new(2, 25, 0.3, 4),
            new(3, 30, 0.2, 6),
            new(4, 70, 0.2, 8),
            new(5, 30, 0.4, 4),
            new(6, 50, 0.3, 6)
        ];

    public ErrorDateTimePoint[] Values3 { get; set; } =
        [
            // (X, Y, Y+- error, Y+- error) // mark
            new(DateTime.Today.AddDays(0), 50, 0.2, 8),
            // (X, Y, X- error, X+ erorr, Y+ error, Y- error) // mark
            new(DateTime.Today.AddDays(1), 45, 0.1, 0.3, 15, 4),
            new(DateTime.Today.AddDays(2), 25, 0.3, 4),
            new(DateTime.Today.AddDays(3), 30, 0.2, 6),
            new(DateTime.Today.AddDays(4), 70, 0.2, 8),
            new(DateTime.Today.AddDays(5), 30, 0.4, 4),
            new(DateTime.Today.AddDays(6), 50, 0.3, 6)
        ];

    public Func<DateTime, string> Formatter { get; set; } =
        date => date.ToString("MMMM dd");
}

XAML

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

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

    <Grid RowDefinitions="*,*,*">
        <lvc:CartesianChart Grid.Row="0">
            <lvc:CartesianChart.Series>
                <lvc:XamlColumnSeries
                    Values="{Binding Values1}"
                    ShowError="True"
                    Padding="0"/>
                <lvc:XamlColumnSeries
                    Values="{Binding Values2}"
                    ShowError="True"
                    Padding="0"/>
            </lvc:CartesianChart.Series>
        </lvc:CartesianChart>

        <lvc:CartesianChart Grid.Row="1">
            <lvc:CartesianChart.Series>
                <lvc:XamlLineSeries
                    Values="{Binding Values1}"
                    ShowError="True"
                    GeometrySize="4"
                    Fill="{x:Null}"/>
            </lvc:CartesianChart.Series>
        </lvc:CartesianChart>

        <lvc:CartesianChart Grid.Row="2">
            <lvc:CartesianChart.Series>
                <lvc:XamlScatterSeries
                    Values="{Binding Values3}"
                    ShowError="True"
                    GeometrySize="10"/>
            </lvc:CartesianChart.Series>
            <lvc:CartesianChart.XAxes>
                <!--
                To get more help about DateTime axes see:
                https://livecharts.dev/docs/avalonia/latest/samples.axes.dateTimeScaled
                -->
                <lvc:XamlDateTimeAxis
                    Interval="1.00:00:00"
                    DateFormatter="{Binding Formatter}"/>
            </lvc:CartesianChart.XAxes>
        </lvc:CartesianChart>
    </Grid>

</UserControl>

Articles you might also find useful: