SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, iOS Chart, Android Chart and JavaScript Chart Components
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)
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
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());
}
Please login first to submit.