Skip to main content

Line chart

info

Charts are available with Avalonia Pro.

Line charts use X and Y axes to visualize data points connected by straight line segments. They are ideal for showing trends over time or categories.

Line chart connecting data points with straight segments to show monthly sales trends over time.

When to use

  • Time series: Visualizing changes in data over continuous time intervals.
  • Trend analysis: Identifying upward, downward, or fluctuating patterns.
  • Multiple series: Comparing trends across different categories using multiple lines.

Code example

XAML

<charts:CartesianChart Name="LineChart" Title="Line Chart" Height="250" ShowLegend="True">
<charts:CartesianChart.HorizontalAxis>
<charts:CategoryAxis />
</charts:CartesianChart.HorizontalAxis>
<charts:CartesianChart.VerticalAxis>
<charts:NumericalAxis />
</charts:CartesianChart.VerticalAxis>
<charts:CartesianChart.Series>
<charts:LineSeries Title="2023" ItemsSource="{Binding LineSeries2023}" Stroke="DodgerBlue" StrokeThickness="2" MarkerSize="6" MarkerFill="DodgerBlue" ShowMarkers="True"/>
<charts:LineSeries Title="2024" ItemsSource="{Binding LineSeries2024}" Stroke="Orange" StrokeThickness="2" MarkerSize="6" MarkerFill="Orange" ShowMarkers="True"/>
</charts:CartesianChart.Series>
</charts:CartesianChart>

Data model (C#)

public ObservableCollection<int> LineSeries2023 { get; } = new()
{
45, 52, 48, 60, 55, 70, 65, 75, 68, 80, 72, 85
};

public ObservableCollection<int> LineSeries2024 { get; } = new()
{
50, 58, 55, 68, 62, 78, 72, 82, 75, 88, 80, 92
};

Common properties

PropertyDescriptionDefault
TitleThe name of the series shown in the legend.null
ItemsSourceThe collection of data items to display.null
CategoryPathPath to the property used for the X-axis (category).null
ValuePathPath to the property used for the Y-axis (value).null
StrokeThe color of the line.Theme-dependent
StrokeThicknessThe thickness of the line.2
ShowMarkersWhether to display individual data point markers. Marker styling is visible only when this is true.false
MarkerSizeThe size of the markers in pixels.8
MarkerShapeThe shape of the markers, such as Circle or Square.Circle
MarkerFillBrush used to fill the markers. When null, the series stroke is used.null
MarkerStrokeBrush used for the marker outlines.null
MarkerStrokeThicknessThickness of the marker outlines. When NaN, the series StrokeThickness is used.NaN