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

AutomaticTimeSpanScaleOptions.AutomaticMeasureUnitsCalculator Property

Gets or sets the automatic date-time measure unit calculator.

Namespace: DevExpress.Xpf.Charts

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

NuGet Package: DevExpress.Wpf.Charts

#Declaration

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

#Property Value

Type Description
ITimeSpanMeasureUnitsCalculator

An object of the class that implements the ITimeSpanMeasureUnitsCalculator interface.

#Example

The automatic time-span scale options allow you to create a measurement unit calculator to determine the current measurement unit if the predefined one does not fit your requirements. Create a class that implements the ITimeSpanMeasureUnitsCalculator interface and assign it to the AutomaticMeasureUnitsCalculator property to use a custom measurement units calculation algorithm:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using DevExpress.Xpf.Charts;

namespace TimeSpanExample {
    public class CustomAutomaticTimeSpanMeasureUnitsCalculator : ITimeSpanMeasureUnitsCalculator {
        public TimeSpanMeasureUnit CalculateMeasureUnit(IEnumerable<Series> series, 
            double axisLength, int pixelsPerUnit, 
            double visualMin, double visualMax, 
            double wholeMin, double wholeMax) {
            double rawMeasureUnit = (visualMax - visualMin) / axisLength * pixelsPerUnit;
            return PickTimeSpanMeasureUnit(rawMeasureUnit);
        }
        static int[] unitMultipliers = { 1, 1000, 60, 60, 24 };
        static TimeSpanMeasureUnit PickTimeSpanMeasureUnit(double milliseconds) {
            double valueStop = 1.0;
            for (int i = 0; i < unitMultipliers.Length; i++) {
                valueStop *= unitMultipliers[i];
                if (milliseconds <= valueStop)
                    return (TimeSpanMeasureUnit)i;
            }
            return TimeSpanMeasureUnit.Hour;
        }
    }
}
See Also