Skip to main content

AutomaticNumericScaleOptions.AutomaticMeasureUnitsCalculator Property

Gets or sets the automatic numeric measure unit calculator.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v24.1.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