The CustomAnnotation
The CustomAnnotation allows to place any Android View at a specific location on a chart:
Note
Examples of the Annotations usage can be found in the SciChart Android Examples Suite as well as on GitHub:
You can place any Android View by passing it into the setContentView(View view) method or an layout id into the setContentId(int layoutId) method..
Position of the CustomAnnotation is defined by the X1
or Y1
coordinate, depending on the axis.
Those values can be accessed via the x1 and y1 properties.
Note
The xAxisId and yAxisId must be supplied if you have axis with non-default Axis Ids, e.g. in multi-axis scenario.
Also, because CustomAnnotation is derived from the AnchorPointAnnotation it can be aligned relative to the X1
or Y1
coordinate by setting the Anchor Points. For more information about the Anchor Points - refer to the corresponding section Annotations APIs article.
Note
To learn more about Annotations in general - please see the Common Annotation Features article.
Create a CustomAnnotation
A simple CustomAnnotation with an ImageView can be added onto a chart using the following code:
// assume the surface has been created and configured before
// create a CustomAnnotation
final CustomAnnotation customAnnotation = new CustomAnnotation(getActivity());
// prepare an ImageView for the CustomAnnotation
ImageView image = new ImageView(getActivity());
image.setImageResource(R.drawable.my_custom_view);
// supply it with ImageView
customAnnotation.setContentView(image);
// specify a desired position
customAnnotation.setX1(4.2d);
customAnnotation.setY1(2d);
// Allow to interact with the annotation in run-time
customAnnotation.setIsEditable(true);
// in a multi-axis scenario, specify the XAxisId and YAxisId
customAnnotation.setXAxisId("BottomAxisId");
customAnnotation.setYAxisId("LeftAxisId");
// add the annotation to the Annotations collection of the surface
surface.getAnnotations().add(customAnnotation);
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.