Custom Separators Interval
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.
View model
using CommunityToolkit.Mvvm.ComponentModel;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using SkiaSharp;
namespace ViewModelsSamples.Axes.CustomSeparatorsInterval;
public partial class ViewModel : ObservableObject
{
public ISeries[] Series { get; set; } =
{
new LineSeries<int> { Values = new[] { 10, 55, 45, 68, 60, 70, 75, 78 } }
};
public Axis[] 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 = new double[] { 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 class LogarithmicPoint
{
public double X { get; set; }
public double Y { get; set; }
}
XAML
<UserControl x:Class="UnoWinUISample.Axes.CustomSeparatorsInterval.View"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
xmlns:vms="using:ViewModelsSamples.Axes.CustomSeparatorsInterval"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart
Series="{Binding Series}"
YAxes="{Binding YAxes}">
</lvc:CartesianChart>
</UserControl>