The CustomAnnotation allows to place any Android View at a specific location on a chart:
CustomAnnotation Features
Please refer to the Common Annotation Features to learn more about the ones inherited from the base class. The particularity of the CustomAnnotation type is that its instances can be used to place any Android View onto a chart. This can be done either by passing an Android View into the setContentView() method or an layout id into the setContentId() method.
Position CustomAnnotation
The position of an CustomAnnotation is defined by the X1,Y1 values. These can be set via the setX1() or setY1() methods.
Also, a CustomAnnotation can be aligned relative to its X1,Y1 position via Anchor Points. Please refer to the corresponding section of the Common Annotation Features article for more information.
In a multi-axis scenario, or if you changed the Ids of your axes, both XAxisId and YAxisId must be set. This can be done via the setAxisId(), setYAxisId() methods.
Create CustomAnnotation
A CustomAnnotation can be added onto a chart using the following code:
Copy Code | |
---|---|
// assume the surface has been created and configured before ISciChartSurface surface; // create a CustomAnnotation CustomAnnotation customAnnotation = new CustomAnnotation(getActivity()); // create a custom View to place on a chart ImageView image = new ImageView(getActivity()); image.setImageResource(R.drawable.my_custom_view); // appoint the custom View to the annotation customAnnotation.setContentView(image); // allow to interact with the annotation in run-time customAnnotation.setEditable(true); // in a multi-axis scenario, specify the XAxisId and YAxisId customAnnotation.setXAxisId("Top_X_Axis"); customAnnotation.setYAxisId("Left_Y_Axis"); // specify anchor points customAnnotation.setHorizontalAnchorPoint(HorizontalAnchorPoint.Center); customAnnotation.setVerticalAnchorPoint(VerticalAnchorPoint.Center); // specify a desired position by setting coordinates customAnnotation.setX1(4.2d); customAnnotation.setY1(2d); // add the annotation to the Annotations collection of the surface Collections.addAll(surface.getAnnotations(), customAnnotation); |
Also, a CustomAnnotation can be created using Chart Builders:
Copy Code | |
---|---|
// create a custom View to place on a chart ImageView image = new ImageView(getActivity()); image.setImageResource(R.drawable.my_custom_view); // create and configure a CustomAnnotation CustomAnnotation customAnnotation = sciChartBuilder.newCustomAnnotation() .withPosition(7.5d, 5d) .withContent(image) .withXAxisId(X_TOP_AXIS) .withYAxisId(Y_LEFT_AXIS) .withIsEditable(true) .build(); |
To learn more about other annotation types, available out of the box in SciChart, please find the comprehensive list in the What Is an Annotation article.