All docs
V19.2
19.2
19.1
The page you are viewing does not exist in version 19.1. This link will take you to the root page.
18.2
The page you are viewing does not exist in version 18.2. This link will take you to the root page.
18.1
The page you are viewing does not exist in version 18.1. This link will take you to the root page.
17.2
The page you are viewing does not exist in version 17.2. This link will take you to the root page.

IAxisLabelFormatter Interface

If implemented by a class, provides a method required for a chart control to format axis labels.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v19.2.dll

Declaration

public interface IAxisLabelFormatter :
    IAxisLabelFormatterCore
Public Interface IAxisLabelFormatter
    Inherits IAxisLabelFormatterCore

Examples

Perform the steps below to create a custom formatter for axis labels:

  • Create a class that inherits the IAxisLabelFormatter interface and implement the interface's GetAxisLabelText method.
  • Assign the newly created class instance to the AxisLabel.Formatter property.

How to: Format Numeric Axis Labels

This example shows how to apply a custom format to a numeric axis's labels.

private void OnFormLoad(object sender, EventArgs e) {
    XYDiagram diagram = (XYDiagram)chartControl1.Diagram;
    AxisLabelFormatter formatter = new AxisLabelFormatter();
    diagram.AxisX.Label.Formatter = formatter;
    diagram.AxisY.Label.Formatter = formatter;
}
public class AxisLabelFormatter : IAxisLabelFormatter {
    public string GetAxisLabelText(object axisValue) {
        return Convert.ToString((double)axisValue / 1000);
    }
}

How to: Format Date-Time Axis Labels

This example shows how to format the date-time axis labels as follows:

private void Form1_Load(object sender, EventArgs e) {

    XYDiagram diagram = chartControl.Diagram as XYDiagram;

    // Configure scale options.
    DateTimeScaleOptions dateTimeScaleOptions = diagram.AxisX.DateTimeScaleOptions;          
    dateTimeScaleOptions.ScaleMode = ScaleMode.Continuous;
    dateTimeScaleOptions.GridAlignment = DateTimeGridAlignment.Day;
    dateTimeScaleOptions.GridSpacing = 7;
    dateTimeScaleOptions.WorkdaysOnly = true;

    // Apply a custom format to axis labels.
    AxisLabel axisLabel = diagram.AxisX.Label;
    axisLabel.Formatter = new AxisLabelFormatter();

}
public class AxisLabelFormatter : IAxisLabelFormatter {
    public string GetAxisLabelText(object axisValue) {
        DateTime value = (DateTime)axisValue;
        return ((value.Day >= 1) && (value.Day <= 7)) ? $"{value.ToString("MMM, d")}" : $"{value.Day}";
    }
}
See Also