Axis Pagination
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.
View model
using System;
using System.Collections.Generic;
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
namespace ViewModelsSamples.Axes.Paging;
public partial class ViewModel : ObservableObject
{
public int[] Values { get; set; } = Fetch();
[ObservableProperty]
public partial double MinLimit { get; set; } = double.NaN;
[ObservableProperty]
public partial double MaxLimit { get; set; } = double.NaN;
[RelayCommand]
public void GoToPage1()
{
MinLimit = -0.5;
MaxLimit = 10.5;
}
[RelayCommand]
public void GoToPage2()
{
MinLimit = 9.5;
MaxLimit = 20.5;
}
[RelayCommand]
public void GoToPage3()
{
MinLimit = 19.5;
MaxLimit = 30.5;
}
[RelayCommand]
public void SeeAll()
{
MinLimit = double.NaN;
MaxLimit = double.NaN;
}
private static int[] Fetch()
{
var random = new Random();
var trend = 100;
var values = new List<int>();
for (var i = 0; i < 100; i++)
{
trend += random.Next(-30, 50);
values.Add(trend);
}
return [.. values];
}
}
XAML
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="MauiSample.Axes.Paging.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.Paging;assembly=ViewModelsSamples"
x:DataType="vms:ViewModel">
<ContentPage.BindingContext>
<vms:ViewModel/>
</ContentPage.BindingContext>
<Grid RowDefinitions="50, *">
<HorizontalStackLayout>
<Button Command="{Binding GoToPage1Command}" Text="Page 1"></Button>
<Button Command="{Binding GoToPage2Command}" Text="Page 2"></Button>
<Button Command="{Binding GoToPage3Command}" Text="Page 3"></Button>
<Button Command="{Binding SeeAllCommand}" Text="Clear"></Button>
</HorizontalStackLayout>
<lvc:CartesianChart
Grid.Row="1"
ZoomMode="X">
<lvc:CartesianChart.Series>
<lvc:SeriesCollection>
<lvc:XamlColumnSeries Values="{Binding Values}"/>
</lvc:SeriesCollection>
</lvc:CartesianChart.Series>
<lvc:CartesianChart.XAxes>
<lvc:AxesCollection>
<lvc:XamlAxis
MinLimit="{Binding MinLimit}"
MaxLimit="{Binding MaxLimit}"/>
</lvc:AxesCollection>
</lvc:CartesianChart.XAxes>
</lvc:CartesianChart>
</Grid>
</ContentPage>