Axis Labels

This sample uses C# 12 features, it also uses features from the CommunityToolkit.Mvvm package, you can learn more about it here.

This web site wraps every sample using a UserControl instance, but LiveCharts controls can be used inside any container.

sample image

View model

using SkiaSharp;
using LiveChartsCore;
using LiveChartsCore.SkiaSharpView;
using LiveChartsCore.SkiaSharpView.Painting;
using LiveChartsCore.Kernel.Sketches;

namespace ViewModelsSamples.Axes.LabelsFormat;

public class ViewModel
{
    public ISeries[] Series { get; set; } = [
        new ColumnSeries<double> { Values = [426, 583, 104] },
        new LineSeries<double>   { Values = [200, 558, 458], Fill = null },
    ];

    public ICartesianAxis[] XAxes { get; set; } = [
        new Axis
        {
            Name = "Salesman/woman",
            // Use the labels property for named or static labels // mark
            Labels = ["Sergio", "Lando", "Lewis"], // mark
            LabelsRotation = 15,
        }
    ];

    public ICartesianAxis[] YAxes { get; set; } = [
        new Axis
        {
            Name = "Salome",
            NamePadding = new LiveChartsCore.Drawing.Padding(0, 15),

            LabelsPaint = new SolidColorPaint
            {
                Color = SKColors.Blue,
                FontFamily = "Times New Roman",
                SKFontStyle = new SKFontStyle(
                    SKFontStyleWeight.ExtraBold,
                    SKFontStyleWidth.Normal,
                    SKFontStyleSlant.Italic)
            },

            // Use the Labeler property to give format to the axis values // mark
            // Now the Y axis labels have a currency format.

            // LiveCharts provides some common formatters
            // in this case we are using the currency formatter.
            Labeler = Labelers.Currency // mark

            // you could also build your own currency formatter
            // for example:
            // Labeler = (value) => value.ToString("C")
            // but the one that LiveCharts provides creates shorter labels when
            // the amount is in millions or trillions
        }
    ];
}

XAML

<UserControl x:Class="WinUISample.Axes.LabelsFormat.View"
            xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
            xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
            xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
            xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
            xmlns:lvc="using:LiveChartsCore.SkiaSharpView.WinUI"
            xmlns:vms="using:ViewModelsSamples.Axes.LabelsFormat"
            mc:Ignorable="d">
    <UserControl.DataContext>
        <vms:ViewModel/>
    </UserControl.DataContext>
    <lvc:CartesianChart
        Series="{Binding Series}"
        XAxes="{Binding XAxes}"
        YAxes="{Binding YAxes}">
    </lvc:CartesianChart>
</UserControl>

Articles you might also find useful: