Specify Both X And Y
The [ObservableObject]
, [ObservableProperty]
and [ICommand]
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.Defaults;
using LiveChartsCore.SkiaSharpView;
namespace ViewModelsSamples.Lines.XY;
public partial class ViewModel : ObservableObject
{
public ISeries[] Series { get; set; } =
{
new LineSeries<ObservablePoint>
{
Values = new ObservablePoint[]
{
new ObservablePoint(0, 4),
new ObservablePoint(1, 3),
new ObservablePoint(3, 8),
new ObservablePoint(18, 6),
new ObservablePoint(20, 12)
}
}
};
}
XAML
<UserControl
x:Class="UnoWinUISample.Lines.XY.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.Lines.XY"
mc:Ignorable="d">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart Series="{Binding Series}"/>
</UserControl>