Line Smoothness

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

sample image

View model

namespace ViewModelsSamples.Lines.Straight;

public class ViewModel
{
    public double[] Values1 { get; set; } =
        [5, 0, 5, 0, 5, 0];

    public double[] Values2 { get; set; } =
        [7, 2, 7, 2, 7, 2];
}

XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
    x:Class="MauiSample.Lines.Straight.View"
    xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
    xmlns:lvc="clr-namespace:LiveChartsCore.SkiaSharpView.Maui;assembly=LiveChartsCore.SkiaSharpView.Maui"
    xmlns:vms="clr-namespace:ViewModelsSamples.Lines.Straight;assembly=ViewModelsSamples"
    x:DataType="vms:ViewModel">

    <ContentPage.BindingContext>
        <vms:ViewModel/>
    </ContentPage.BindingContext>

    <!--
    The line smoothness property controls the curve between points
    it goes from 0 to 1, where 0 is straight and 1 is the most curved.
    -->

    <lvc:CartesianChart>
        <lvc:CartesianChart.Series>
            <lvc:SeriesCollection>
                <lvc:XamlLineSeries
                    Values="{Binding Values1}"
                    Fill="{x:Null}"
                    GeometrySize="0"
                    LineSmoothness="0"/>

                <lvc:XamlLineSeries
                    Values="{Binding Values2}"
                    Fill="{x:Null}"
                    GeometrySize="0"
                    LineSmoothness="1"/>
            </lvc:SeriesCollection>
        </lvc:CartesianChart.Series>
    </lvc:CartesianChart>
</ContentPage>

Articles you might also find useful: