The FreehandDrawingAnnotationCreationModifier
The FreehandDrawingModifier is a chart modifier that allows for freehand creation of FreehandDrawingAnnotation instances.
Overview
When this modifier is enabled and added to a SciChartSurface, users can draw freehand strokes directly on the chart using touch gestures. The modifier automatically creates a new FreehandDrawingAnnotation and populates it with points based on the user's movement.
Properties
The following properties can be used to configure the FreehandDrawingModifier:
| Property | Description |
|---|---|
| brushColor | Sets the color of the brush stroke for the annotations created by this modifier. |
| brushThickness | Sets the thickness of the brush stroke for the annotations created by this modifier. |
| 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. |
Event Listeners
You can receive a notification when an annotation is created by setting an OnAnnotationCreatedListener:
- setAnnotationCreationListener(OnAnnotationCreatedListener listener): Passes the newly created annotation instance to the listener.
Using FreehandDrawingModifier
The following code demonstrates how to add and configure a FreehandDrawingModifier:
// Create a FreehandDrawingModifier
final FreehandDrawingModifier freehandModifier = new FreehandDrawingModifier();
// Configure the modifier
freehandModifier.setBrushColor(Color.WHITE);
freehandModifier.setBrushThickness(4f);
// Optional: Set a listener to be notified when an annotation is created
freehandModifier.setAnnotationCreationListener(newAnnotation -> {
// Configure the newly created annotation if needed
newAnnotation.setIsEditable(true);
});
// Add the modifier to the surface
surface.getChartModifiers().add(freehandModifier);
Customizing the Modifier
You can customize the behavior of the FreehandDrawingModifier by extending it and overriding its touch event methods. This allows you to add custom logic before or after an annotation is created.
// Define a custom FreehandDrawingModifier
private static class CustomFreehandDrawingModifier extends FreehandDrawingModifier {
@Override
protected boolean onTouchDown(ModifierTouchEventArgs args) {
// Custom logic before creation
return super.onTouchDown(args);
}
@Override
protected boolean onTouchMove(ModifierTouchEventArgs args) {
// Custom logic during creation
return super.onTouchMove(args);
}
@Override
protected boolean onTouchUp(ModifierTouchEventArgs args) {
// Custom logic after creation
return super.onTouchUp(args);
}
}
void useCustomFreehandDrawingModifier(@NonNull SciChartSurface surface) {
// Use the custom modifier
final CustomFreehandDrawingModifier customModifier = new CustomFreehandDrawingModifier();
customModifier.setBrushColor(Color.YELLOW);
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.