SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components

Answered
0
0

Hello there,

I’m trying to implement adding line annotation on touch, but this causes crash.

I’m watching example android app in fragment CreateAnnotationsDynamicallyFragment.

I guess, it should be very easy, but example uses data binding and part of code is hidden somewhere + source code is obfuscated, so it’s hard for me to understand what is wrong.

Can someone give a short example of how to add annotation on touch?

Thanks

Exception:

 Process: process_name, PID: 24978
java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Comparable com.scichart.charting.visuals.axes.IAxis.getDataValue(float)' on a null object reference
    at com.scichart.charting.modifiers.AnnotationCreationModifier.a(SourceFile:203)
    at com.scichart.charting.modifiers.AnnotationCreationModifier.onTouchDown(SourceFile:155)
Version
2.2.2.2433
  • You must to post comments
Best Answer
0
0

Hi Vadim,

We have an example in our demo application which shows how to do it. Based on your exception I would say that annotation created by modifier have incorrect AxisId for X or Y axis. This can happen if you change Id of axis but forgot to set the same id in AnnotationCreationModifier or any other case when for some reason annotation can’t locate associated X/YAxis. I would suggest to check id of axis which you use and ensure that you set the same id for modifier:

    // set ids which should be set to new annotations
    annotationCreationModifier.setXAxisId(xAxisIdToUseWhenCreatingAnnotation);
    annotationCreationModifier.setYAxisId(yAxisIdToUseWhenCreatingAnnotation);

Best regards,
Yura

  • You must to post comments
0
0

Hi Yura,

This is how i did it, but still crashing on touch:

private void initDrawingAnnotations() {
    annotationCreationModifier = new AnnotationCreationModifier();

    DefaultAnnotationFactory annotationFactory = new DefaultAnnotationFactory();

    annotationFactory.setFactoryForAnnotationType(DefaultAnnotationFactory.LINE_ANNOTATION, new IAnnotationFactory() {
        @Override
        public IAnnotation createAnnotation(ISciChartSurface parentSurface, int annotationType) {
            return sciChartBuilder.newLineAnnotation()
                    .withXAxisId(SURFACE_MAIN_X_AXIS_ID)
                    .withYAxisId(SURFACE_MAIN_Y_AXIS_ID)
                    .withStroke(1, Color.RED)
                    .withIsEditable(true)
                    .build();
        }
    });
    annotationCreationModifier.setAnnotationFactory(annotationFactory);
    mSciChartMainSurface.getChartModifiers().add(sciChartBuilder.newModifierGroup().withModifier(annotationCreationModifier).build());
}
  • Yura Khariton
    Please try to use code from my answer because modifier will override XAxisId/YAxisId which you set in factory with values from modifier’s XAxisId/YAxisId properties. If this doesn’t help please attach entire project which reproduces this issue.
  • Kirey Vadim
    Thanks, it worked
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.

SciChart WPF v6 BETA released! Note pricing/licensing changes are coming. Contact us to beat the rise!Read more
+