Dashed Lines

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.Design.StrokeDashArray;

public class ViewModel
{
    public int[] Values { get; set; } =
        [4, 2, 8, 5, 3];
}

XAML

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

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

    <lvc:CartesianChart>
        <lvc:CartesianChart.Series>
            <lvc:XamlLineSeries
                Values="{Binding Values}"
                LineSmoothness="1"
                GeometrySize="22"
                Stroke="{lvc:SolidColorPaint
                    Color='#6495ED',
                    StrokeCap=Round,
                    StrokeWidth=10,
                    PathEffect={lvc:Dashed Array='30, 20'}}"
                Fill="{x:Null}"/>
        </lvc:CartesianChart.Series>
    </lvc:CartesianChart>

</UserControl>