AutomaticDateTimeScaleOptions.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 IDateTimeMeasureUnitsCalculator AutomaticMeasureUnitsCalculator { get; set; }
Property Value
Type | Description |
---|---|
IDateTimeMeasureUnitsCalculator | An object of the class implementing the IDateTimeMeasureUnitsCalculator interface. |
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