Skip to main content

IDateTimeMeasureUnitsCalculator.CalculateMeasureUnit(IEnumerable<Series>, Double, Int32, Double, Double, Double, Double) Method

Calculates the date-time measurement unit that an axis should use for display.

Namespace: DevExpress.Xpf.Charts

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

Declaration

DateTimeMeasureUnit CalculateMeasureUnit(
    IEnumerable<Series> series,
    double axisLength,
    int pixelsPerUnit,
    double visualMin,
    double visualMax,
    double wholeMin,
    double wholeMax
)

Parameters

Name Type Description
series IEnumerable<Series>

All Series associated with the axis.

axisLength Double

The length of the axis’s visual range in pixels.

pixelsPerUnit Int32

The minimum count of pixels that series require to draw their points correctly.

visualMin Double

The visual range’s minimum value in milliseconds.

visualMax Double

The visual range’s maximum value in milliseconds.

wholeMin Double

The whole range’s minimum value in milliseconds.

wholeMax Double

The whole range’s maximum value in milliseconds.

Returns

Type Description
DateTimeMeasureUnit

The calculated measurement unit.

Remarks

For example, bars can overlap each other if the calculated measurement unit covers fewer pixels on the axis than the pixelPerUnit parameter specifies.

Example

The automatic date-time 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. Create a class that implements the IDateTimeMeasureUnitsCalculator interface and assign it to the AutomaticDateTimeScaleOptions.AutomaticMeasureUnitsCalculator property to use a custom measurement units calculation algorithm:

public class CustomAutomaticDateTimeMeasureUnitsCalculator : IDateTimeMeasureUnitsCalculator {
    public DateTimeMeasureUnit CalculateMeasureUnit(
        IEnumerable<Series> series, 
        double axisLength, int pixelsPerUnit, 
        double visualMin, double visualMax, 
        double wholeMin, double wholeMax
    ) {
        double rawMeasureUnit = ((visualMax - visualMin) * pixelsPerUnit / axisLength);
        return PickDateTimeMeasureUnit(rawMeasureUnit);
    }

    static int[] unitMultipliers = {
        1, 1000, 60, 60, 24, 7, 4, 3, 4
    };
    static DateTimeMeasureUnit PickDateTimeMeasureUnit(double milliseconds) {
        double valueStop = 1.0;
        for (int i = 0; i < unitMultipliers.Length; i++) {
            valueStop *= unitMultipliers[i];
            if (milliseconds <= valueStop)
                return (DateTimeMeasureUnit)i;
        }
        return DateTimeMeasureUnit.Year;
    }
}
See Also