AutomaticTimeSpanScaleOptions.AutomaticMeasureUnitsCalculator Property
In This Article
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 |
---|---|
ITime |
An object of the class that implements the ITime |
#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