Skip to main content

Axis customization

info

Charts are available with Avalonia Pro.

Avalonia Charts lets you customize axis appearance, including label fitting, axis line styling, tick marks, gridline configuration, and multi-axis support.

Cartesian chart with customized axes showing gridlines.

When to use

  • Multiple scales: When displaying two different metrics (e.g., Temperature and Humidity) on the same chart.
  • Categorical data: When axes represent discrete groups rather than continuous numbers.
  • Time-Series analysis: Customizing date formats and intervals for historical data.

Code example

XAML

<charts:CartesianChart Name="GridLinesChart" Title="Dashed Major Grid Lines" Height="300">
<charts:CartesianChart.HorizontalAxis>
<charts:CategoryAxis ShowGridLines="True" GridLineBrush="#BBDEFB" GridLineStrokeThickness="2">
<charts:CategoryAxis.GridLineDashStyle>
<DashStyle Dashes="5,5"/>
</charts:CategoryAxis.GridLineDashStyle>
</charts:CategoryAxis>
</charts:CartesianChart.HorizontalAxis>
<charts:CartesianChart.VerticalAxis>
<charts:NumericalAxis ShowGridLines="True" GridLineBrush="#C8E6C9" GridLineStrokeThickness="2">
<charts:NumericalAxis.GridLineDashStyle>
<DashStyle Dashes="10,5"/>
</charts:NumericalAxis.GridLineDashStyle>
</charts:NumericalAxis>
</charts:CartesianChart.VerticalAxis>
<charts:CartesianChart.Series>
<charts:AreaSeries Title="Data" ItemsSource="{Binding SalesData}" Fill="#7E2196F3" Stroke="#2196F3" />
</charts:CartesianChart.Series>
</charts:CartesianChart>

Data model (C#)

public ObservableCollection<int> SalesData { get; } = new() { 35, 28, 34, 32, 40, 32, 35 };

Common axis properties (NumericalAxis / CategoryAxis)

PropertyDescriptionDefault
TitleThe text label for the axis.null
IsVisibleToggle the visibility of the entire axis.true
TitleFontSizeFont size used for the axis title.14.0
TitleForegroundBrush used for the axis title.null
ShowLabelsWhether to draw axis labels.true
LabelFontSizeFont size used for axis labels.12.0
LabelForegroundBrush used for axis labels.null
ShowAxisLineWhether to draw the axis baseline.true
AxisLineStrokeBrush used for the axis baseline. When null, the chart axis brush is used.null
AxisLineStrokeThicknessThickness of the axis baseline.1.0
AxisLineDashStyleDash style for the axis baseline.null
ShowTickLinesWhether to draw tick marks at label positions.false
TickLineLengthLength of tick marks in pixels.5.0
TickLineStrokeBrush used for tick marks. When null, the chart axis brush is used.null
TickLineStrokeThicknessThickness of tick marks.1.0
ShowGridLinesShow/hide major grid lines.true
ShowMinorGridLinesShow/hide minor grid lines.false
GridLineBrushBrush used for major grid lines.null
GridLineStrokeThicknessThickness of major grid lines.1.0
GridLineDashStyleDash style for major grid lines.null
GridLineCapLine cap style for major grid lines.Flat
GridLineJoinLine join style for major grid lines.Miter
MinorGridLineBrushBrush used for minor grid lines.null
MinorGridLineStrokeThicknessThickness of minor grid lines.0.5
MinorGridLineDashStyleDash style for minor grid lines.null
MinorGridLineCapLine cap style for minor grid lines.Flat
MinorGridLineJoinLine join style for minor grid lines.Miter
LabelFormatFormat string for labels (e.g., "C0", "N2", "yyyy").null
LabelRotationCustom rotation angle used when LabelFitMode is CustomRotation.0.0
MinorTickCountNumber of minor intervals between major ticks.4
LabelFitModeStrategy used when labels do not fit. Values include None, Hide, Wrap, MultipleRows, Rotate45, Rotate90, CustomRotation, and Auto.None

Axis types

AxisDescriptionSupports
NumericalAxisFor continuous numeric data.Minimum, Maximum, MajorStep, MinorStep, ScaleBreaks
CategoryAxisFor discrete categories.GapLength, PlotMode
DateTimeAxisFor date and time data.Minimum, Maximum, MajorStep, MajorStepUnit, DateFormat
LogarithmicAxisFor data with a large range.Minimum, Maximum, LogBase, MajorStep

Scale breaks

Use NumericalAxis.ScaleBreaks for inline XAML scale breaks or ScaleBreaksSource to bind a collection from a view model. Scale breaks skip ranges that would otherwise compress the visible data. Each ScaleBreak defines a removed value range and optional break-line styling. Invalid ranges where End <= Start are ignored, and overlapping or adjacent breaks are merged before the axis range is normalized.

PropertyDescriptionDefault
StartFirst value in the skipped axis range.0.0
EndLast value in the skipped axis range.0.0
StrokeBrush used to draw the scale break marks.null
StrokeThicknessThickness of the scale break marks.1.0

Axis-specific properties

AxisPropertyDescriptionDefault
NumericalAxisMinimumExplicit minimum value. When null, the chart calculates it from data.null
NumericalAxisMaximumExplicit maximum value. When null, the chart calculates it from data.null
NumericalAxisMajorStepMajor tick interval. Invalid or non-positive values fall back to an automatic step.null
NumericalAxisMinorStepMinor tick interval.null
NumericalAxisScaleBreaksInline collection of scale breaks.Empty collection
NumericalAxisScaleBreaksSourceBound collection used instead of ScaleBreaks when set.null
DateTimeAxisMinimumExplicit minimum date. When null, the chart calculates it from data.null
DateTimeAxisMaximumExplicit maximum date. When null, the chart calculates it from data.null
DateTimeAxisMajorStepMajor tick interval combined with MajorStepUnit. Month and year steps are rounded to whole units.1.0
DateTimeAxisMajorStepUnitUnit used by MajorStep: Second, Minute, Hour, Day, Week, Month, or Year.Day
DateTimeAxisDateFormatOptional date label format string.null
LogarithmicAxisMinimumExplicit positive minimum value. When null, the chart calculates it from data.null
LogarithmicAxisMaximumExplicit positive maximum value. When null, the chart calculates it from data.null
LogarithmicAxisLogBaseLogarithm base used for the axis scale.10.0
LogarithmicAxisMajorStepMajor tick multiplier. When null, the axis calculates it from LogBase.null

Continuous horizontal axes

CartesianChart can render supported series against a continuous horizontal NumericalAxis, LogarithmicAxis, or DateTimeAxis. The chart uses continuous horizontal layout only when every visible non-empty series supports it and each horizontal category value can be converted to the selected axis type.

Supported Cartesian series include LineSeries, SplineSeries, StepLineSeries, AreaSeries, SplineAreaSeries, AreaRangeSeries, ScatterSeries, ScatterLineSeries, BubbleSeries, and ErrorBarSeries. ChartTrendlineSeries and MovingAverageSeries follow the compatibility of their SourceSeries when one is set.

For DateTimeAxis, CategoryPath values must resolve to DateTime or DateTimeOffset. For NumericalAxis and LogarithmicAxis, values must resolve to finite numeric values. LogarithmicAxis requires values greater than 0.

If any visible non-empty series is incompatible, the chart uses category layout for the horizontal axis.

Plot bands

Use ChartAxis.PlotBands to shade ranges on a horizontal or vertical axis. On a category axis, horizontal-axis plot band Start and End values use category indexes. On a continuous horizontal axis, they use the axis value domain.

PropertyDescriptionDefault
StartStart value of the shaded range. When NaN, the band starts at the beginning of the axis.NaN
EndEnd value of the shaded range. When NaN, the band ends at the end of the axis.NaN
FillBrush used to fill the band.null
StrokeBrush used for the band border.null
StrokeThicknessThickness of the band border.0.0
OpacityOpacity applied to the band fill.0.3
TextOptional text drawn inside the band.null
ForegroundBrush used for plot band text.null
TextFontSizeFont size used for plot band text.12.0
HorizontalTextAlignmentHorizontal text alignment within the band: Start, Center, or End.Center
VerticalTextAlignmentVertical text alignment within the band: Start, Center, or End.Center
IsVisibleWhether the plot band is rendered.true
IsRepeatingWhether the band repeats at regular axis intervals.false
RepeatEveryAxis interval between repeated bands. When repeating is enabled with an invalid value, it is set to 1.0.NaN
RepeatUntilAxis value where repeated bands stop.NaN
RenderAboveSeriesWhether to render the band above the chart series instead of behind them.false

See also