The XabcdAnnotationCreationModifier
The XabcdAnnotationCreationModifier is a chart modifier that allows for interactive creation of XabcdAnnotation instances using a multi-tap workflow.
Overview
When this modifier is enabled, users can place the 5 required points (X, A, B, C, D) by tapping on the chart.
- Each tap confirms the position of the next point.
- A "rubber-band" dashed line provides a preview of the next segment between the last confirmed point and the current touch position.
- Once the fifth point (D) is placed, the annotation is finalized, and the modifier automatically resets to create the next one.
Properties
The following properties can be used to configure the XabcdAnnotationCreationModifier:
| Property | Description |
|---|---|
| xAxisId | Sets the ID of the X-Axis that the created annotations should be measured against. |
| yAxisId | Sets the ID of the Y-Axis that the created annotations should be measured against. |
| rubberBandStroke | Sets the pen style for the preview line shown during creation. |
Event Listeners
You can receive a notification when an annotation is fully created by setting an OnAnnotationCreatedListener:
- setAnnotationCreationListener(OnAnnotationCreatedListener listener): Passes the newly created annotation instance to the listener.
Using XabcdAnnotationCreationModifier
The following code demonstrates how to add and configure an XabcdAnnotationCreationModifier:
// Create an XabcdAnnotationCreationModifier
final XabcdAnnotationCreationModifier xabcdCreationModifier = new XabcdAnnotationCreationModifier();
// Optional: Set a listener to be notified when an annotation is created
xabcdCreationModifier.setAnnotationCreationListener(newAnnotation -> {
// Configure the newly created annotation if needed
newAnnotation.setIsEditable(true);
});
// Add the modifier to the surface
surface.getChartModifiers().add(xabcdCreationModifier);
Customizing the Modifier
The XabcdAnnotationCreationModifier is designed for extensibility. You can customize its behavior by extending it and overriding its protected methods. This allows you to change the annotation type, customize the rubber-band preview, or add post-creation logic.
// Define a custom XabcdAnnotationCreationModifier
private static class CustomXabcdAnnotationCreationModifier extends XabcdAnnotationCreationModifier {
@Override
protected void configureRubberBandAnnotation(IAnnotation annotation) {
super.configureRubberBandAnnotation(annotation);
// Customize the rubber-band styling
if (annotation instanceof LineAnnotation) {
((LineAnnotation) annotation).setStroke(new SolidPenStyle(Color.YELLOW, true, 2f, new float[]{10, 5}));
}
}
@Override
protected void onAnnotationCreated(IAnnotation newAnnotation) {
super.onAnnotationCreated(newAnnotation);
// Custom logic after annotation is fully created
newAnnotation.setIsEditable(true);
}
}
void useCustomXabcdAnnotationCreationModifier(@NonNull SciChartSurface surface) {
// Use the custom modifier
final CustomXabcdAnnotationCreationModifier customModifier = new CustomXabcdAnnotationCreationModifier();
surface.getChartModifiers().add(customModifier);
}
Note
To learn more about other Annotation Types, available out of the box in SciChart, please find the comprehensive list in the Annotation APIs article.