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

ITimeSpanMeasureUnitsCalculator.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.v24.2.dll

NuGet Package: DevExpress.Wpf.Charts

#Declaration

TimeSpanMeasureUnit 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
TimeSpanMeasureUnit

The calculated measurement unit.

#Remarks

Bars can overlap each other if the calculated measurement unit covers fewer pixels on the axis than the pixelPerUnit parameter specifies.

#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