INumericMeasureUnitsCalculator.CalculateMeasureUnit(IEnumerable<Series>, Double, Int32, Double, Double, Double, Double) Method
Calculates the numeric 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
double CalculateMeasureUnit(
IEnumerable<Series> series,
double axisLength,
int pixelsPerUnit,
double visualMin,
double visualMax,
double wholeMin,
double wholeMax
)
Parameters
Name | Type | Description |
---|---|---|
series | IEnumerable<Series> | |
axisLength | Double | The length of the axis’s current 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. |
visualMax | Double | The visual range’s maximum value. |
wholeMin | Double | The whole range’s minimum value. |
wholeMax | Double | The whole range’s maximum value. |
Returns
Type | Description |
---|---|
Double | 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 numeric 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. Design a class that implements the INumericMeasureUnitsCalculator interface and assign it to the AutomaticNumericScaleOptions.AutomaticMeasureUnitsCalculator property to use a custom measurement units calculation algorithm:
public class CustomAutomaticNumericMeasureUnitsCalculator : INumericMeasureUnitsCalculator {
public double CalculateMeasureUnit(
IEnumerable<Series> series,
double axisLength, int pixelsPerUnit,
double visualMin, double visualMax,
double wholeMin, double wholeMax
) {
double rawMeasureUnit = (visualMax - visualMin) * pixelsPerUnit / axisLength;
return Math.Pow(10, GetDigitCount((int)Math.Abs(rawMeasureUnit)));
}
private static readonly int[] valueStops = {
9, 99, 999, 9999, 99999, 999999, 9999999,
99999999, 999999999, Int32.MaxValue
};
private static int GetDigitCount(int value) {
for (int i = 0; ; i++)
if (value <= valueStops[i])
return i + 1;
}
}