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)
- Kirey Vadim asked 5 years ago
- You must login to post comments
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
- Yura Khariton answered 5 years ago
- You must login to post comments
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());
}
- Kirey Vadim answered 5 years ago
- last edited 5 years ago
-
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.
-
Thanks, it worked
- You must login to post comments
Please login first to submit.