Basic Line


Hover over the image to see the chart animation
This sample uses C# 12 features, it also uses features from the CommunityToolkit.Mvvm package, you can learn more about it here.
View Model
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Drawing.Geometries;
using LiveChartsCore.SkiaSharpView.VisualElements;
namespace ViewModelsSamples.Lines.Basic;
public class ViewModel
{
public ISeries[] Series { get; set; } = [
new LineSeries<double>
{
Values = [2, 1, 3, 5, 3, 4, 6],
Fill = null,
GeometrySize = 20
},
new LineSeries<int, StarGeometry>
{
Values = [4, 2, 5, 2, 4, 5, 3],
Fill = null,
GeometrySize = 20,
}
];
public LabelVisual Title { get; set; } =
new LabelVisual
{
Text = "My chart title",
TextSize = 25,
Padding = new LiveChartsCore.Drawing.Padding(15)
};
}
XAML
<UserControl x:Class="AvaloniaSample.Lines.Basic.View"
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:lvc="using:LiveChartsCore.SkiaSharpView.Avalonia"
xmlns:vms="using:ViewModelsSamples.Lines.Basic">
<UserControl.DataContext>
<vms:ViewModel/>
</UserControl.DataContext>
<lvc:CartesianChart
Series="{Binding Series}"
Title="{Binding Title}">
</lvc:CartesianChart>
</UserControl>