Skip to main content

DevExpress v24.2 Update — Your Feedback Matters

Our What's New in v24.2 webpage includes product-specific surveys. Your response to our survey questions will help us measure product satisfaction for features released in this major update and help us refine our plans for our next major release.

Take the survey Not interested

IAxisLabelFormatter Interface

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

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v24.2.dll

NuGet Package: DevExpress.Wpf.Charts

#Declaration

public interface IAxisLabelFormatter :
    IAxisLabelFormatterCore

The following members return IAxisLabelFormatter objects:

#Example

Perform the steps below to create a formatter:

  • Create a class that inherits the IAxisLabelFormatter interface and implement the interface’s GetAxisLabelText method.
  • Assign the newly created class’s 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.

Markup:

<dxc:XYDiagram2D.AxisX>
    <dxc:AxisX2D>
        <dxc:AxisX2D.Label>
            <dxc:AxisLabel>
                <dxc:AxisLabel.Formatter>
                    <local:AxisLabelFormatter/>
                </dxc:AxisLabel.Formatter>
            </dxc:AxisLabel>
        </dxc:AxisX2D.Label>
    </dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>
<dxc:XYDiagram2D.AxisY>
    <dxc:AxisY2D>
            <dxc:AxisLabel>
                <dxc:AxisLabel.Formatter>
                    <local:AxisLabelFormatter/>
                </dxc:AxisLabel.Formatter>
            </dxc:AxisLabel>
        </dxc:AxisY2D.Label>
    </dxc:AxisY2D>
</dxc:XYDiagram2D.AxisY>

Code-Behind:

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:

Markup:

<dxc:XYDiagram2D.AxisX>
    <dxc:AxisX2D>
        <dxc:AxisX2D.DateTimeScaleOptions>
            <dxc:ManualDateTimeScaleOptions AutoGrid="False" 
                                            GridAlignment="Day" 
                                            GridSpacing="7"/>
        </dxc:AxisX2D.DateTimeScaleOptions>
        <dxc:AxisX2D.Label>
            <dxc:AxisLabel>
                <dxc:Axis2D.ResolveOverlappingOptions>
                    <dxc:AxisLabelResolveOverlappingOptions AllowHide="False"/>
                </dxc:Axis2D.ResolveOverlappingOptions>
                <dxc:AxisLabel.Formatter>
                    <local:AxisLabelFormatter/>
                </dxc:AxisLabel.Formatter>
            </dxc:AxisLabel>
        </dxc:AxisX2D.Label>
    </dxc:AxisX2D>
</dxc:XYDiagram2D.AxisX>

Code-Behind:

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