Skip to main content

Annotations

info

Charts are available with Avalonia Pro.

Annotations allow you to add context to your charts using lines, bands, shapes, and custom text. They are useful for highlighting thresholds, milestones, or specific regions of interest.

Chart with annotation overlays including a horizontal threshold line, a shaded comfort zone band, and a custom text label.

When to use

  • Thresholds: Showing a "target" or "limit" line on a performance chart.
  • Milestones: Marking specific dates of interest on a timeline.
  • Region highlighting: Shading a "danger zone" or "comfort zone" across a set of values.

Code example

XAML

<charts:CartesianChart Name="ShapesChart" Height="250">
<charts:CartesianChart.HorizontalAxis>
<charts:NumericalAxis Title="X" Minimum="0" Maximum="10" />
</charts:CartesianChart.HorizontalAxis>
<charts:CartesianChart.VerticalAxis>
<charts:NumericalAxis Title="Y" Minimum="0" Maximum="100" />
</charts:CartesianChart.VerticalAxis>
<charts:CartesianChart.Series>
<charts:ScatterSeries Title="Points" ItemsSource="{Binding ShapeData}"
CategoryPath="X" ValuePath="Y" MarkerSize="8" />
</charts:CartesianChart.Series>
<charts:CartesianChart.Annotations>
<!-- Highlight Region -->
<charts:RectangleAnnotation X="0.6" Y="60" Width="0.2" Height="20"
Stroke="Blue" Label="Region A">
<charts:RectangleAnnotation.Fill>
<SolidColorBrush Color="#280000FF" />
</charts:RectangleAnnotation.Fill>
</charts:RectangleAnnotation>
<!-- Circle of Interest -->
<charts:EllipseAnnotation X="0.3" Y="30" RadiusX="0.05" RadiusY="5"
Stroke="Orange" Label="Cluster">
<charts:EllipseAnnotation.Fill>
<SolidColorBrush Color="#28FFA500" />
</charts:EllipseAnnotation.Fill>
</charts:EllipseAnnotation>
<!-- Trend Arrow -->
<charts:ArrowLineAnnotation X1="0.3" Y1="35" X2="0.7" Y2="65"
Stroke="Purple" StrokeThickness="2" ShowEndArrow="True" Label="Growth" />
</charts:CartesianChart.Annotations>
</charts:CartesianChart>

Data model (C#)

public record Point(double X, double Y);

public ObservableCollection<Point> ShapeData { get; } = new()
{
new(3, 30),
new(7, 70)
};

Coordinate system

Annotation coordinates are specified in axis space. On category axes, horizontal values use zero-based category slot indexes. On continuous horizontal axes, horizontal values use the axis value domain, such as numeric values or DateTime ticks. Vertical values use the vertical axis value domain.

Shape sizes are also measured in axis units. On logarithmic axes or axes with scale breaks, the same data delta can map to different pixel sizes depending on its origin. Custom annotation renderers should use CartesianAnnotationRenderContext.DataXToPixel and DataYToPixel for positions, and DeltaXToPixelsAt(origin, value) or DeltaYToPixelsAt(origin, value) for origin-sensitive sizes.

Common properties (LineAnnotation)

PropertyDescriptionDefault
ValueAxis-space value where the line is placed. Horizontal lines use vertical-axis values; vertical lines use horizontal-axis values.0
OrientationHorizontal or Vertical.Horizontal
StrokeColor of the annotation line.Gray
StrokeThicknessWidth of the annotation line.1.0
DashStyleDash style used for the annotation line.null
ForegroundBrush used for the label text. When null, the annotation falls back to Stroke where supported.null
FontSizeFont size used for annotation labels.12.0
LabelText displayed next to the line.null

Common properties (BandAnnotation)

PropertyDescriptionDefault
FromValueStarting axis-space value of the band. Horizontal bands use vertical-axis values; vertical bands use horizontal-axis values.0
ToValueEnding axis-space value of the band.0
OrientationHorizontal or Vertical.Horizontal
FillThe brush used to fill the shaded area.null
ForegroundBrush used for the band label text. When null, the annotation falls back to Stroke where supported.null
FontSizeFont size used for the band label.12.0
LabelText displayed inside the band.null

Common properties (TextAnnotation)

A text annotation placed at a specific coordinate on the chart area.

PropertyDescriptionDefault
XHorizontal-axis value. Category axes use zero-based category slot indexes.0
YVertical-axis value.0
TextText displayed by the annotation.null
ForegroundBrush used for the text fill.null
FontSizeFont size used for the text.12.0
StrokeOptional text outline brush. Text outlines are drawn only when Stroke is explicitly set.Gray
StrokeThicknessOptional text outline thickness. Applied only when Stroke is explicitly set.1.0
OpacityOpacity of the annotation.1.0

Common properties (RectangleAnnotation)

A rectangle annotation placed at specific coordinates on the chart area.

PropertyDescriptionDefault
XLeft horizontal-axis value. Category axes use zero-based category slot indexes.0
YLower vertical-axis value.0
WidthWidth in horizontal-axis units.0.5
HeightHeight in vertical-axis units.10.0
FillBrush used to fill the rectangle.null
CornerRadiusCorner radius for rounded rectangles.0
LabelText displayed at the center of the rectangle.null
StrokeColor of the rectangle border.Gray
StrokeThicknessWidth of the rectangle border.1
ForegroundBrush used for the rectangle label text.null
FontSizeFont size used for the rectangle label.12.0
OpacityOpacity of the annotation.1.0

XAML

<charts:CartesianChart Height="250">
<charts:CartesianChart.Annotations>
<charts:RectangleAnnotation X="0.2" Y="50" Width="0.3" Height="20"
Stroke="DarkGreen" StrokeThickness="2"
CornerRadius="4" Label="Target Zone">
<charts:RectangleAnnotation.Fill>
<SolidColorBrush Color="#3200FF00" />
</charts:RectangleAnnotation.Fill>
</charts:RectangleAnnotation>
</charts:CartesianChart.Annotations>
</charts:CartesianChart>

Common properties (EllipseAnnotation)

An ellipse annotation placed at specific coordinates on the chart area.

PropertyDescriptionDefault
XCenter horizontal-axis value. Category axes use zero-based category slot indexes.0
YCenter vertical-axis value.0
RadiusXHorizontal radius in axis units.0.25
RadiusYVertical radius in axis units.10.0
FillBrush used to fill the ellipse.null
LabelText displayed at the center of the ellipse.null
StrokeColor of the ellipse border.Gray
StrokeThicknessWidth of the ellipse border.1
ForegroundBrush used for the ellipse label text.null
FontSizeFont size used for the ellipse label.12.0
OpacityOpacity of the annotation.1.0

XAML

<charts:CartesianChart Height="250">
<charts:CartesianChart.Annotations>
<charts:EllipseAnnotation X="0.5" Y="60" RadiusX="0.15" RadiusY="15"
Stroke="Purple" StrokeThickness="2"
Label="Anomaly">
<charts:EllipseAnnotation.Fill>
<SolidColorBrush Color="#32800080" />
</charts:EllipseAnnotation.Fill>
</charts:EllipseAnnotation>
</charts:CartesianChart.Annotations>
</charts:CartesianChart>

Common properties (ArrowLineAnnotation)

A line annotation with optional arrowheads at either or both ends, useful for indicating direction or drawing attention between two data points.

PropertyDescriptionDefault
X1Start horizontal-axis value. Category axes use zero-based category slot indexes.0
Y1Start vertical-axis value.0
X2End horizontal-axis value.0
Y2End vertical-axis value.0
ShowStartArrowWhether to show an arrowhead at the start.false
ShowEndArrowWhether to show an arrowhead at the end.true
ArrowSizeSize of the arrowhead in pixels.8.0
LabelText displayed at the midpoint of the line.null
StrokeColor of the arrow line.Gray
StrokeThicknessWidth of the arrow line.1
ForegroundBrush used for the arrow label text.null
FontSizeFont size used for the arrow label.12.0
OpacityOpacity of the annotation.1.0

XAML

<charts:CartesianChart Height="250">
<charts:CartesianChart.Annotations>
<charts:ArrowLineAnnotation X1="0.1" Y1="30" X2="0.6" Y2="80"
Stroke="OrangeRed" StrokeThickness="2"
ShowEndArrow="True" ArrowSize="10"
Label="Upward trend" />
</charts:CartesianChart.Annotations>
</charts:CartesianChart>