Axes
A CartesianChart has two collections of axes, XAxes and YAxes. When a collection is not set, or is empty, the
chart uses one default Axis for it. An axis sets the range of the data that is visible, and draws the name, the
labels, the separators and the ticks:

This article highlights the most used features. Every property is listed in the API explorer: Axis.
Style
Every part of the axis has its own paint:
NamePaintdraws theName, withNameTextSize(20by default) andNamePadding.LabelsPaintdraws the labels, withTextSize(16by default).SeparatorsPaintdraws a line across the chart at each label, andSubseparatorsPaintdrawsSubseparatorsCount(3by default) thinner lines between them.TicksPaintdraws a short tick next to each label, andSubticksPaintthe ticks between them. WhenDrawTicksPathistrue,TicksPaintalso draws the axis line.ZeroPaintdraws a line at the value0.
A paint that is null is not drawn. The default theme sets NamePaint and LabelsPaint on every axis, and
SeparatorsPaint only on the Y axes, so a default chart has horizontal separators and no vertical ones.
ShowSeparatorLines hides the separators and subseparators without removing their paints.

@page "/Axes/Style"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.Defaults;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting;
@using LiveChartsCore.SkiaSharpView.Painting.Effects;
@using SkiaSharp;
<div style="background-color: #333333; padding: 20px">
<CartesianChart
Series="@series"
XAxes="@xAxes"
YAxes="@yAxes"
DrawMarginFrame="@frame"
ZoomMode="LiveChartsCore.Measure.ZoomAndPanMode.Both"
TooltipPosition="LiveChartsCore.Measure.TooltipPosition.Hidden">
</CartesianChart>
</div>
@code {
private ObservablePoint[] values;
private ISeries[] series;
private Axis[] xAxes;
private Axis[] yAxes;
private DrawMarginFrame frame;
// for simplicity we use the page constructor
public View()
{
values = new ObservablePoint[1001];
var fx = EasingFunctions.BounceInOut;
for (var i = 0; i < 1001; i++)
{
var x = i / 1000f;
var y = fx(x);
values[i] = new ObservablePoint(x - 0.5, y - 0.5);
}
var gray = new SKColor(195, 195, 195);
var gray1 = new SKColor(160, 160, 160);
var gray2 = new SKColor(90, 90, 90);
var gray3 = new SKColor(60, 60, 60);
series = new ISeries[]
{
new LineSeries<ObservablePoint>
{
Values = values,
Stroke = new SolidColorPaint(new SKColor(33, 150, 243), 4),
Fill = null,
GeometryFill = null,
GeometryStroke = null
}
};
var dashEffect = new DashEffect(new float[] { 3, 3 });
xAxes = new Axis[]
{
new Axis
{
Name = "X Axis",
NamePaint = new SolidColorPaint(gray1),
TextSize = 18,
LabelsPaint = new SolidColorPaint(gray),
SeparatorsPaint = new SolidColorPaint(gray, 1) { PathEffect = dashEffect },
SubseparatorsPaint = new SolidColorPaint(gray2, 0.5f),
SubseparatorsCount = 9,
ZeroPaint = new SolidColorPaint(gray1, 2),
TicksPaint = new SolidColorPaint(gray, 1.5f),
SubticksPaint = new SolidColorPaint(gray, 1)
}
};
yAxes = new Axis[]
{
new Axis
{
Name = "Y Axis",
NamePaint = new SolidColorPaint(gray1),
TextSize = 18,
LabelsPaint = new SolidColorPaint(gray),
SeparatorsPaint = new SolidColorPaint(gray, 1) { PathEffect = dashEffect },
SubseparatorsPaint = new SolidColorPaint(gray2, 0.5f),
SubseparatorsCount = 9,
ZeroPaint = new SolidColorPaint(gray1, 2),
TicksPaint = new SolidColorPaint(gray, 1.5f),
SubticksPaint = new SolidColorPaint(gray, 1)
}
};
frame = new DrawMarginFrame
{
Stroke = new SolidColorPaint(gray, 2)
};
}
}
The same kind of paints set in code:

XAxes = new Axis[]
{
new Axis
{
Name = "X Axis",
NamePaint = new SolidColorPaint(SKColors.Black), // mark
LabelsPaint = new SolidColorPaint(SKColors.Blue), // mark
TextSize = 10,
SeparatorsPaint = new SolidColorPaint(SKColors.LightSlateGray) { StrokeThickness = 2 } // mark
}
};
YAxes = new Axis[]
{
new Axis
{
Name = "Y Axis",
NamePaint = new SolidColorPaint(SKColors.Red), // mark
LabelsPaint = new SolidColorPaint(SKColors.Green), // mark
TextSize = 20,
SeparatorsPaint = new SolidColorPaint(SKColors.LightSlateGray) // mark
{ // mark
StrokeThickness = 2, // mark
PathEffect = new DashEffect(new float[] { 3, 3 }) // mark
} // mark
}
};
Paints can also draw gradients and dashed lines, see the Paints article.
Position
Position places the axis at the Start or at the End of the chart. Start, the default, is the bottom for an
X axis and the left for a Y axis; End is the top for an X axis and the right for a Y axis.

YAxes = new Axis[]
{
new Axis
{
Position = LiveChartsCore.Measure.AxisPosition.End // mark
}
};
Labels and labelers
There are two ways to set the text of the labels:
Labelsis a list of strings. The label at a value is the item at that index, so it fits series where each point is a category: the first point is at0, the second at1and so on. Values outside the list get an empty label. WhileLabelsis set, the step between labels is never less than1.Labeleris a function that takes the value and returns the label. TheLabelersclass has some ready to use, such asLabelers.Currency, which also shortens millions, billions and trillions (M,B,T).
When Labels is set, Labeler is ignored. This sample names the categories of the X axis with Labels, formats the
Y axis as currency with a Labeler, and changes the font of the Y labels in its LabelsPaint.

@page "/Axes/LabelsFormat"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting;
@using SkiaSharp;
<CartesianChart Series="@series"
XAxes="@xAxes"
YAxes="@yAxes">
</CartesianChart>
@code {
private static double[] values1 = new double[] { 426, 583, 104 };
private static double[] values2 = new double[] { 200, 558, 458 };
private static string[] labels = new string[] { "Sergio", "Lando", "Lewis" };
private static string Labeler(double value) => value.ToString("C2");
private ISeries[] series = new ISeries[]
{
new ColumnSeries<double> { Values = values1 },
new ColumnSeries<double> { Values = values2, Fill = null }
};
private Axis[] xAxes = new Axis[]
{
new Axis
{
Name = "Salesman/woman",
Labels = labels
}
};
private Axis[] yAxes = new Axis[]
{
new Axis
{
Name = "Sales",
NamePadding = new LiveChartsCore.Drawing.Padding(0, 15),
Labeler = Labeler,
LabelsPaint = new SolidColorPaint(SKColors.Blue)
{
SKTypeface = SKTypeface.FromFamilyName(
"Times New Roman",
SKFontStyleWeight.ExtraBold,
SKFontStyleWidth.Normal,
SKFontStyleSlant.Italic)
}
}
};
}
The same in code, with the currency labeler of the library:
XAxes = new Axis[]
{
new Axis
{
Labels = new string[] { "Anne", "Johnny", "Zac", "Rosa" } // mark
}
};
YAxes = new Axis[]
{
new Axis
{
Labeler = Labelers.Currency // mark
// or your own format, for example:
// Labeler = value => value.ToString("C")
}
};
When Labeler is not set, the axis uses Labelers.Default. To change it for every axis in your app, call
Labelers.SetDefaultLabeler(...) before the axes are created.
Non-Latin labels
When the font of a paint has no glyph for a character, LiveCharts asks the system for a font that has it, so labels
in Chinese, Arabic or other scripts are drawn without extra setup. To pick the font yourself, set the SKTypeface
of the paint, for example SKTypeface.FromFamilyName("Noto Sans SC").

@page "/Axes/LabelsFormat2"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting;
@using SkiaSharp;
<CartesianChart Series="@series"
XAxes="@xAxes"
YAxes="@yAxes">
</CartesianChart>
@code {
private static double[] values1 = new double[] { 426, 583, 104 };
private static double[] values2 = new double[] { 200, 558, 458 };
private static string[] labels = new string[] { "王", "赵", "张" };
private static string Labeler(double value) => value.ToString("C2");
private ISeries[] series = new ISeries[]
{
new ColumnSeries<double> { Values = values1 },
new ColumnSeries<double> { Values = values2, Fill = null }
};
private Axis[] xAxes = new Axis[]
{
new Axis
{
Name = "Salesman/woman",
Labels = labels
}
};
private Axis[] yAxes = new Axis[]
{
new Axis
{
Name = "Sales",
NamePadding = new LiveChartsCore.Drawing.Padding(0, 15),
Labeler = Labeler,
LabelsPaint = new SolidColorPaint(SKColors.Blue)
{
SKTypeface = SKTypeface.FromFamilyName(
"Times New Roman",
SKFontStyleWeight.ExtraBold,
SKFontStyleWidth.Normal,
SKFontStyleSlant.Italic)
}
}
};
// protected override async Task OnInitializedAsync()
// {
// Register a font that supports Chinese characters (optional, for full compatibility)
// this must be defined when the app starts not here... this is just an example,
// see App.razor.cs for a better place to do this
// we need to load a font that supports Chinese characters
// for example the Source Han Sans CN Light.otf, that is in the wwwroot folder
// https://github.com/Live-Charts/LiveCharts2/tree/f904fac8988c4792d2570e8245736e33479e1238/samples/BlazorSample
// var httpClient = new HttpClient { BaseAddress = new("https://localhost:7277") };
// var fontStream = await httpClient.GetStreamAsync("Source Han Sans CN Light.otf");
// var typeface = SKTypeface.FromStream(fontStream);
// LiveCharts.Configure(config =>
// config.HasTextSettings(new TextSettings
// {
// DefaultTypeface = typeface
// }));
// }
}
Labels rotation
LabelsRotation rotates the labels, in degrees. This chart rotates the Y labels 45 degrees:

YAxes = new Axis[]
{
new Axis
{
LabelsRotation = 45 // mark
}
};
Labels density
The axis calculates how many labels fit, based on the data, the size of the chart and the size of the labels.
LabelsDensity changes the space it leaves between them: 0 is the most dense, larger values separate the labels
more, and values below 0 let them overlap. The default is 0.85. It is not used while the labels are rotated
between 20 and 70 degrees.

Step
The step is the distance between two labels, in data units. The axis calculates it and rounds it to 1, 2 or 5 times a power of ten. Three properties control it:
MinStepis the smallest step allowed,0by default. Set it to1to never show decimal labels.ForceStepToMinusesMinStepas the step, always. Be careful with a small step on a large range: the axis draws every separator.MinSeparatorsis the minimum number of separators the calculated step must produce,3by default. When the rounding leaves fewer, the step is divided further. Set it to0to disable it. It is ignored whenForceStepToMinistrue.
YAxes = new Axis[]
{
new Axis
{
MinStep = 1 // mark
}
};
Custom separators
CustomSeparators sets the exact values where the separators and labels go, instead of placing them every step. This
sample places them at 0, 10, 25, 50 and 100, and sets the limits of the axis to 0 and 100.

@page "/Axes/CustomSeparatorsInterval"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting
@using SkiaSharp
<CartesianChart
Series="@series"
YAxes="@yAxes">
</CartesianChart>
@code {
private ISeries[] series = new ISeries[]
{
new LineSeries<int> { Values = new int[] { 10, 55, 45, 68, 60, 70, 75, 78 } }
};
private Axis yAxis;
private Axis[] yAxes;
// for simplicity we use the page constructor
public View()
{
var customSeparators = new double[] { 0, 10, 25, 50, 100 };
yAxis = new Axis
{
CustomSeparators = customSeparators,
MinLimit = 0,
MaxLimit = 100,
SeparatorsPaint = new SolidColorPaint(new SKColor(180, 180, 180, 100))
};
yAxes = new[] { yAxis };
}
}
Limits
MinLimit and MaxLimit set the visible range of the axis, points outside it are not visible. Both are null by
default, and null (or double.NaN) means the axis takes the limit from the data. For example, to show only the
first 10 points of a series (paging):
var xAxis = new Axis
{
MinLimit = 0, // mark
MaxLimit = 10 // mark
};
XAxes = new Axis[] { xAxis };
Zooming and panning change both properties, see
zooming and panning,
which also shows how to clear the zoom. Axis implements INotifyPropertyChanged, so you can listen to every change
of the visible range, made by code or by the user:
xAxis.PropertyChanged += (sender, e) =>
{
if (e.PropertyName is nameof(Axis.MinLimit) or nameof(Axis.MaxLimit))
{
var min = xAxis.MinLimit;
var max = xAxis.MaxLimit;
}
};
While the limits are null, read DataBounds (the range of the data) and VisibleDataBounds (the range of the
visible data) instead. They are set when the chart is measured, so read them in the UpdateStarted event of the
chart, or later.
Inverted axes
An X axis grows to the right and a Y axis grows up. Set IsInverted to true to reverse the direction of an axis.
Hidden axes
When IsVisible is false the axis is not drawn and takes no space in the chart. The series keep using it to scale.
Unit width
UnitWidth is the width of one data point in data units, 1 by default. Bar series (columns and rows) and financial
series use it to size each point. Change it when the distance between two points is not 1, which is normally the
case in date time scales, see
time and logarithmic scales.
XAxes = new Axis[]
{
new Axis
{
// the X values are DateTime ticks and there is one point per day
UnitWidth = TimeSpan.FromDays(1).Ticks // mark
}
};
Multiple axes
Add more than one axis to XAxes or YAxes, and choose the axis of each series with ScalesXAt and ScalesYAt,
the index of the axis in the collection (0 by default). Axes on the same side are placed side by side; the first
one in the collection is the farthest from the series. In this sample the two "tens" series scale at the first Y axis,
and the other two at their own axes on the right, which hide their separators with ShowSeparatorLines.

@page "/Axes/Multiple"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting;
@using SkiaSharp;
<CartesianChart
Series="@series"
YAxes="@yAxes"
LegendPosition="LiveChartsCore.Measure.LegendPosition.Left"
LegendBackgroundPaint="@legendBackgroundPaint"
LegendTextPaint="@legendTextPaint"
LegendTextSize="16">
</CartesianChart>
@code {
private static double[] values1 = new double[] { 14, 13, 14, 15, 17 };
private static double[] values2 = new double[] { 11, 12, 13, 10, 13 };
private static double[] values3 = new double[] { 533, 586, 425, 579, 518 };
private static double[] values4 = new double[] { 5493, 7843, 4368, 9018, 3902 };
private static SKColor blue = new SKColor(25, 118, 210);
private static SKColor red = new SKColor(229, 57, 53);
private static SKColor yellow = new SKColor(198, 167, 0);
private static SKColor legendBg = new SKColor(238, 238, 238);
private static SKColor legendText = new SKColor(50, 50, 50);
private ISeries[] series = new ISeries[]
{
new LineSeries<double>
{
Name = "Tens",
Values = values1,
Stroke = new SolidColorPaint(blue, 2),
GeometryStroke = new SolidColorPaint(blue, 2),
Fill = null,
ScalesYAt = 0
},
new LineSeries<double>
{
Name = "Tens 2",
Values = values2,
Stroke = new SolidColorPaint(blue, 2),
GeometryStroke = new SolidColorPaint(blue, 2),
Fill = null,
ScalesYAt = 0
},
new LineSeries<double>
{
Name = "Hundreds",
Values = values3,
Stroke = new SolidColorPaint(red, 2),
GeometryStroke = new SolidColorPaint(red, 2),
Fill = null,
ScalesYAt = 1
},
new LineSeries<double>
{
Name = "Thousands",
Values = values4,
Stroke = new SolidColorPaint(yellow, 2),
GeometryStroke = new SolidColorPaint(yellow, 2),
Fill = null,
ScalesYAt = 2
}
};
private Axis[] yAxes = new Axis[]
{
new Axis {
Name = "Tens",
Padding = new LiveChartsCore.Drawing.Padding(0, 0, 20, 0),
NamePaint = new SolidColorPaint(blue),
LabelsPaint = new SolidColorPaint(blue),
TicksPaint = new SolidColorPaint(blue),
SubticksPaint = new SolidColorPaint(blue)
},
new Axis {
Name = "Hundreds",
Padding = new LiveChartsCore.Drawing.Padding(20, 0, 0, 0),
Position = LiveChartsCore.Measure.AxisPosition.End,
ShowSeparatorLines = false,
NamePaint = new SolidColorPaint(red),
LabelsPaint = new SolidColorPaint(red),
TicksPaint = new SolidColorPaint(red),
SubticksPaint = new SolidColorPaint(red)
},
new Axis {
Name = "Thousands",
Padding = new LiveChartsCore.Drawing.Padding(20, 0, 0, 0),
Position = LiveChartsCore.Measure.AxisPosition.End,
ShowSeparatorLines = false,
NamePaint = new SolidColorPaint(yellow),
LabelsPaint = new SolidColorPaint(yellow),
TicksPaint = new SolidColorPaint(yellow),
SubticksPaint = new SolidColorPaint(yellow)
}
};
private SolidColorPaint legendBackgroundPaint = new SolidColorPaint(legendBg);
private SolidColorPaint legendTextPaint = new SolidColorPaint(legendText);
}
Shared axes
Shared axes keep two or more charts aligned: the range of each axis includes the data of the others, and zooming,
panning and crosshairs in one chart are applied to the others. Create one axis per chart and share them with
SharedAxes.Set. The
labels can have different widths in each chart, so set the same left DrawMargin in both to align them.
var xAxis1 = new Axis();
var xAxis2 = new Axis();
SharedAxes.Set(xAxis1, xAxis2); // mark
chart1.XAxes = new Axis[] { xAxis1 };
chart2.XAxes = new Axis[] { xAxis2 };
Match the axes scale
By default each axis fits its own range, so one unit on the X axis and one unit on the Y axis can take a different
number of pixels. Set MatchAxesScreenDataRatio to true on the chart and both take the same number of pixels per
unit, at any size, zoom or pan. This sample also forces the same step on both axes, so the separators draw squares.
It only works with one X axis and one Y axis.

@page "/Axes/MatchScale"
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore;
@using LiveChartsCore.Defaults;
@using LiveChartsCore.SkiaSharpView;
@using LiveChartsCore.SkiaSharpView.Painting;
@using SkiaSharp;
<div>
<CartesianChart
Series="@series"
XAxes="@xAxes"
YAxes="@yAxes"
DrawMarginFrame="@frame"
MatchAxesScreenDataRatio="true"
ZoomMode="LiveChartsCore.Measure.ZoomAndPanMode.Both"
TooltipPosition="LiveChartsCore.Measure.TooltipPosition.Hidden">
</CartesianChart>
</div>
@code {
private ObservablePoint[] values;
private ISeries[] series;
private Axis[] xAxes;
private Axis[] yAxes;
private DrawMarginFrame frame;
// for simplicity we use the page constructor
public View()
{
values = new ObservablePoint[1001];
var fx = EasingFunctions.BounceInOut;
for (var i = 0; i < 1001; i++)
{
var x = i / 1000f;
var y = fx(x);
values[i] = new ObservablePoint(x - 0.5, y - 0.5);
}
series = new ISeries[]
{
new LineSeries<ObservablePoint>
{
Values = values,
Stroke = new SolidColorPaint(new SKColor(33, 150, 243, 255), 4), // DeepSkyBlue
Fill = null,
GeometryStroke = null,
GeometryFill = null
}
};
var separatorColor = new SKColor(180, 180, 180, 100); // #64b4b4b4
// we are forcing the step to 0.1 to highlight that
// both axes take the same amount of pixels per unit of data,
// but in a real scenario the MinStep is not necessary
xAxes = new Axis[]
{
new Axis
{
Name = "XAxis",
SeparatorsPaint = new SolidColorPaint(separatorColor),
MinStep = 0.1,
ForceStepToMin = true
}
};
yAxes = new Axis[]
{
new Axis
{
Name = "YAxis",
SeparatorsPaint = new SolidColorPaint(separatorColor),
MinStep = 0.1,
ForceStepToMin = true
}
};
frame = new DrawMarginFrame
{
Stroke = new SolidColorPaint(separatorColor, 2)
};
}
}
using LiveChartsCore;
using LiveChartsCore.Kernel.Sketches;
using LiveChartsCore.Measure;
namespace ViewModelsSamples.Axes.MatchScale;
public static class CustomScaleExtensions
{
// the DrawMarginDefined event is called once the chart // mark
// has defined the area where the series will be drawn // mark
// ignoring the axes, titles, and legends // mark
// this is where we modify the axes limits to define our custom scale // mark
public static void DoubleY(this ICartesianChartView chart) =>
((CartesianChartEngine)chart.CoreChart).DrawMarginDefined += OnDrawMarginDefined;
// we are defining the limits of the Y axes to take the double of pixels per unit of data // mark
private static void OnDrawMarginDefined(CartesianChartEngine chart)
{
var x = chart.XAxes[0];
var y = chart.YAxes[0];
var xMin = x.MinLimit ?? x.DataBounds.Min;
var xMax = x.MaxLimit ?? x.DataBounds.Max;
// validating the limits ensures that when the chart is empty
// the axis limits use a rasonable default value.
AxisLimit.ValidateLimits(ref xMin, ref xMax, x.MinStep);
x.SetLimits(xMin, xMax, notify: false);
var xScreenDataRatio = chart.DrawMarginSize.Width / (xMax - xMin);
// with some omitted Algebra, we know that the required range
// in the Y axis needs to satisfy the next formula:
// yDelta = height / (xScreenDataRatio * timesScale)
const int timesScale = 2;
var yDelta = chart.DrawMarginSize.Height / (xScreenDataRatio * timesScale);
var midY = GetMidPoint(y);
// finally we set the limits of the Y axis
// to +-0.5 * yDelta from the mid point
y.SetLimits(
midY - 0.5f * yDelta,
midY + 0.5f * yDelta,
notify: false);
// it is important to use notify: false // mark
// to avoid the chart to update once we set the limits. // mark
}
private static double GetMidPoint(ICartesianAxis axis)
{
var min = axis.MinLimit ?? axis.DataBounds.Min;
var max = axis.MaxLimit ?? axis.DataBounds.Max;
return (min + max) * 0.5f;
}
}
using System;
using LiveChartsCore;
using LiveChartsCore.Drawing;
using LiveChartsCore.Kernel.Sketches;
namespace ViewModelsSamples.Axes.MatchScale;
public static class InchScaleExtensions
{
// the DrawMarginDefined event is called once the chart // mark
// has defined the area where the series will be drawn // mark
// ignoring the axes, titles, and legends // mark
// this is where we modify the axes limits to define our custom scale // mark
public static void InchSeparator(this ICartesianChartView chart) =>
((CartesianChartEngine)chart.CoreChart).DrawMarginDefined += OnDrawMarginDefined;
// we will force the axis step to be 1 inch long // mark
private static void OnDrawMarginDefined(CartesianChartEngine chart)
{
var dataPerInch = GetDataPerInch((ICartesianChartView)chart.View);
// knowing the data per inch, we can set an step that will, in this case 1 inch
var inches = 1d;
var x = chart.XAxes[0];
var xMin = x.MinLimit ?? x.DataBounds.Min;
var xMax = x.MaxLimit ?? x.DataBounds.Max;
var xStep = inches * dataPerInch.X;
x.SetLimits(xMin, xMax, xStep, notify: false);
var y = chart.YAxes[0];
var yMin = y.MinLimit ?? y.DataBounds.Min;
var yMax = y.MaxLimit ?? y.DataBounds.Max;
var yStep = inches * dataPerInch.Y;
y.SetLimits(yMin, yMax, yStep, notify: false);
// it is important to use notify: false // mark
// to avoid the chart to update once we set the limits. // mark
}
private static LvcPointD GetDataPerInch(ICartesianChartView chart)
{
var p0 = chart.ScaleDataToPixels(new(0, 0));
var p1 = chart.ScaleDataToPixels(new(1, 1));
// calculate the distance between 0,0 and 1,1 in pixels
var pux = Math.Abs(p0.X - p1.X);
var puy = Math.Abs(p0.Y - p1.Y);
var ppi = GetPixelsPerInch();
// calculate the data per inch
var dpix = ppi / pux;
var dpiy = ppi / puy;
return new LvcPointD(dpix, dpiy);
}
// this is an example, in a real scenario you should get the screen PPI
private static double GetPixelsPerInch() => 96.0;
}
The chart does this in its DrawMarginDefined event, which runs once the chart knows the area of the series and
before the axes are drawn; there, the limits of the axes can be changed with SetLimits(..., notify: false). The
sample includes two other scales built the same way: CustomScaleExtensions gives the Y axis twice the pixels per
unit of the X axis, and InchScaleExtensions makes the separators one inch apart (it assumes 96 pixels per inch,
read the real value of the screen in your app). To use one, remove MatchAxesScreenDataRatio and call it with the
chart control:
CustomScaleExtensions.DoubleY(myChart); // mark
Related features
- Zooming and panning, and how to clear them, are covered in zooming and panning.
- Date time, time span and logarithmic axes are covered in time and logarithmic scales.
- Crosshairs are set on the axes, see tooltips and crosshairs.
