Pre loader

Specify the distance between major-axis in exact Millimetres or Centimetres

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums

0
0

Hi everyone,

I’m working on a 2D chart on Android that requires the distance between major axes to be exactly 5 millimetres. How do I configure the major axis delta/ticks or resize the chart to meet my need?

Thank you.

Version
3.0.0.4253
  • You must to post comments
0
0

Hi Natasya,

Well you can create custom TickProvider with DeltaCalculator to calculate desired dimensions:

public class CustomNumericTickProvider extends NumericTickProvider {
    private final CustomNumericDeltaCalculator deltaCalculator;

    public CustomNumericTickProvider(float majorTickSizeMm) {
        this(new CustomNumericDeltaCalculator(majorTickSizeMm));
    }

    public CustomNumericTickProvider(CustomNumericDeltaCalculator deltaCalculator){
        super(deltaCalculator);
        this.deltaCalculator = deltaCalculator;
    }

    @Override
    public void attachTo(IServiceContainer services) {
        super.attachTo(services);

        deltaCalculator.axis = axis;
    }

    @Override
    public void detach() {
        deltaCalculator.axis = null;

        super.detach();
    }

    public static class CustomNumericDeltaCalculator extends NumericDeltaCalculator {
        private final float majorSizeInPixels;
        private IAxisCore axis;

        public CustomNumericDeltaCalculator(float majorSizeMm) {
            // calculate how many device pixels are in 5mm on screen
            majorSizeInPixels = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_MM, majorSizeMm, Resources.getSystem().getDisplayMetrics());
        }

        @Override
        protected IAxisDelta<Double> calculateDeltaInternal(double min, double max, int minorsPerMajor, int maxTicks) {
            final ICoordinateCalculator coordCalc = axis.getCurrentCoordinateCalculator();

            // calculate how many data representation of 5mm for current VisibleRange
            final double doubleDelta = Math.abs(coordCalc.getDataValue(majorSizeInPixels) - coordCalc.getDataValue(0f));

            return new AxisDelta<>(doubleDelta / minorsPerMajor, doubleDelta);
        }
    }
}

Then apply it for both X and Y axes:

    xAxis.setTickProvider(new CustomNumericTickProvider(5f));
    yAxis.setTickProvider(new CustomNumericTickProvider(5f));

Is this suitable for your needs?

Best regards,
Yura

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.