Get started
Three steps: add the packages, dress the page, draw a line. Everything else on this page is what to read after that.
1. Add the packages
dotnet add package AvCharts.Controls
AvCharts.Controls brings the chart control, data tips, the legend and the colour
tokens, and depends on AvCharts - the model half, which is axes, transforms, series
and the drawing kernel, and which never touches Avalonia.Controls.
2. Dress the page
Every colour a chart draws is a token in one resource dictionary, in a light and a dark set. One line, and every chart on the page is dressed:
<Application.Resources>
<ResourceInclude Source="avares://AvCharts.Controls/Themes/ChartTheme.axaml" />
</Application.Resources>
Overriding a token is putting a value under the same key; replacing the look outright is writing
your own ControlTheme under the same type key. A chart follows the variant of
whatever it is put into, so a dark chart on a light page is a
ThemeVariantScope and nothing more.
3. Draw a line
using Avalonia.Controls;
using AvCharts.Charts;
using AvCharts.Controls;
var chart = new CartesianChart
{
HorizontalAxis = new DateTimeAxis(),
VerticalAxis = new LinearAxis(),
};
chart.Series.Add(new LineSeries<Reading>
{
DisplayName = "Depth",
ItemsSource = readings,
XSelector = reading => reading.When,
YSelector = reading => reading.Depth,
});
// A column chart with a line over it is two series on one chart, and a second
// vertical scale is a series with an axis of its own.
chart.Series.Add(new ColumnSeries<Reading> { /* ... */ });
A series can be a line, a step line, an area, a plot of marks, a bubble, a column or a bar, and columns come clustered, overlaid or stacked. The gallery has a page for each of those, with knobs on it.
Where to go next
What it is built for
- Many readings, not many charts. A hundred thousand read and drawn in about thirty milliseconds; a frame of panning in twelve; a hit test on them in seventy microseconds. Sampling is built in, and it is applied where the readings are, not by asking for less data.
- Readings that are missing are said to be missing. A gap, a line joined over it, or a zero - never an invented value.
- The window belongs to the reader. Wheel zoom anchored at the pointer, drag panning, and a fixed scale where a unit of data keeps its pixels whatever the control's size.
- Extension is a shape, not an inheritance tree. A custom series is four overrides; a custom axis brings its own ladder of intervals; a marker is an interface; a threshold or a band is a chart element; a coordinate system of your own is a transform.