Custom Separators Interval

This sample uses C# 12 features, 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

using SkiaSharp;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.Kernel.Sketches;

namespace ViewModelsSamples.Axes.CustomSeparatorsInterval;

public class ViewModel
{
    public ISeries[] Series { get; set; } = [
        new LineSeries<int> { Values = [10, 55, 45, 68, 60, 70, 75, 78] }
    ];

    public ICartesianAxis[] YAxes { get; set; } = [
        new Axis
        {
            // We can specify a custom separator collection
            // the library will use this separators instead of
            // calculating them based on the date of the chart
            CustomSeparators = [0, 10, 25, 50, 100],
            MinLimit = 0, // forces the axis to start at 0
            MaxLimit = 100, // forces the axis to end at 100
            SeparatorsPaint = new SolidColorPaint(SKColors.Black.WithAlpha(100))
        }
    ];
}

LogarithmicPoint.cs

namespace ViewModelsSamples.Axes.Logarithmic;

public struct LogarithmicPoint
{
    public double X { get; set; }
    public double Y { get; set; }
}

XAML

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage x:Class="MauiSample.Axes.CustomSeparatorsInterval.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.Axes.CustomSeparatorsInterval;assembly=ViewModelsSamples"
             >
    <ContentPage.BindingContext>
        <vms:ViewModel/>
    </ContentPage.BindingContext>
    <lvc:CartesianChart
        Series="{Binding Series}"
        YAxes="{Binding YAxes}">
    </lvc:CartesianChart>
</ContentPage>

Articles you might also find useful: