How to: Use Custom Measure Units in an Automatic Numeric Scale Mode

  • 2 minutes to read

To use a custom Numeric measure unit for an Automatic scale mode, assign an object of a class implementing the INumericMeasureUnitsCalculator interface to the NumericScaleOptions.AutomaticMeasureUnitsCalculator property of AxisBase.NumericScaleOptions.

    private void Form1_Load(object sender, EventArgs e) {

        XYDiagram diagram = chart.Diagram as XYDiagram;
        if (diagram == null) return;

        diagram.AxisX.NumericScaleOptions.AggregateFunction = AggregateFunction.Average;
        diagram.AxisX.NumericScaleOptions.ScaleMode = ScaleMode.Automatic;
        diagram.AxisX.NumericScaleOptions.AutomaticMeasureUnitsCalculator = new CustomNumericMeasureUnitCalculator();

        diagram.AxisY.WholeRange.AlwaysShowZeroLevel = false;
class CustomNumericMeasureUnitCalculator : INumericMeasureUnitsCalculator {
    public double CalculateMeasureUnit(
            IEnumerable<Series> series, 
            double axisLength, 
            int pixelsPerUnit, 
            double visualMin, 
            double visualMax, 
            double wholeMin, 
            double wholeMax) {
        double visualRange = visualMax - visualMin;
        return Math.Ceiling(visualRange / 20);