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

AutomaticNumericScaleOptions.AutomaticMeasureUnitsCalculator Property

Gets or sets the automatic numeric measure unit calculator.

Namespace: DevExpress.Xpf.Charts

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

NuGet Package: DevExpress.Wpf.Charts

#Declaration

[Browsable(false)]
public INumericMeasureUnitsCalculator AutomaticMeasureUnitsCalculator { get; set; }

#Property Value

Type Description
INumericMeasureUnitsCalculator

An object of the class implementing the INumericMeasureUnitsCalculator interface.

#Example

The automatic numeric scale options provide the capability to use a custom measurement unit calculator to determine the current measurement unit if the predefined one does not fit your requirements. Design a class that implements the INumericMeasureUnitsCalculator interface and assign it to the AutomaticNumericScaleOptions.AutomaticMeasureUnitsCalculator property to use a custom measurement units calculation algorithm:

public class CustomAutomaticNumericMeasureUnitsCalculator : INumericMeasureUnitsCalculator {
    public double CalculateMeasureUnit(
        IEnumerable<Series> series, 
        double axisLength, int pixelsPerUnit, 
        double visualMin, double visualMax, 
        double wholeMin, double wholeMax
    ) {
        double rawMeasureUnit = (visualMax - visualMin) * pixelsPerUnit / axisLength;
        return Math.Pow(10, GetDigitCount((int)Math.Abs(rawMeasureUnit)));
    }

    private static readonly int[] valueStops = {
        9, 99, 999, 9999, 99999, 999999, 9999999,
        99999999, 999999999, Int32.MaxValue
    };
    private static int GetDigitCount(int value) {
        for (int i = 0; ; i++)
            if (value <= valueStops[i])
                return i + 1;
    }
}
See Also