Creating the Annotation Extension Object

Once you have added the reference to the Annotation assembly in your project, you are ready to create the Annotation Extension object. The Annotation Extension object must be created as a type AnnotationX. Once created, the Extension object may be added to the chart using the Chart class Extensions property. Below is an example of creating the Annotation Extension and adding it to the chart.


SoftwareFX.ChartFX.Annotation.AnnotationX annot = new SoftwareFX.ChartFX.Annotation.AnnotationX();
chart1.getExtensions().add(annot);

Configuring the Annotation List Object

Every Annotation Extension object created will include an Annotation Object List. The Annotation Object List consists of all the individual annotation objects that you wish to appear in your chart. To add floating text, you would simply create an annotation text object, set the desired attributes and add that object to the Annotation List. As long as the Extension object has been added to the chart, the text object will appear in the chart. Below is an example:


SoftwareFX.ChartFX.Annotation.AnnotationText text = new SoftwareFX.ChartFX.Annotation.AnnotationText();
annot.getList().add(text);
text.setText("This is an Annotation");
text.setColor(java.awt.Color.RED);
text.attach(3,50);

By using the List property of the AnnotationX class, you may access methods and properties that allow you to add, clear, count, remove and access particular elements in the Annotation Object List. To clear all the objects currently included in the object list you can use the following code:


annot.getList().clear();

Creating Instances of Annotation Objects

There are a variety of different Annotation objects that are exposed when you add the Annotation Extension to your project. The following objects may be included in your charting applications by implementing the Annotation Extension:

  • Arc (AnnotationArc class)
  • Arrow (AnnotationArrow class)
  • Balloon (AnnotationBalloon class)
  • Circle (AnnotationCircle class)
  • Group (AnnotationGroup class)
  • Picture (AnnotationPicture class)
  • Polygon (AnnotationPolygon class)
  • Rectangle (AnnotationRectangle class)
  • Text (AnnotationText class)

Annotation objects and their properties belong to another class. This means you should create a new instance of an object with the "New" clause in order to access the supported class members. The code below will create a new annotation circle object and add the object to the Annotation Object List:


AnnotationCircle circle = new AnnotationCircle();
annot.getList().add(circle);

Once the circle object has been created, you may begin to assign supported attributes to the object. The circle object does not expose any additional properties or methods; rather it shares a set of common properties (AnnotationObject class) that may be applied to any of the annotation objects. Other objects expose specific properties that must be set to display the object appropriately in the chart area. For example, all objects expose the Top and Left properties that allow you to position the element; additionally the annotation arrow object also exposes a specific property TailStyle, which allows you to configure the arrow tail style.

Below is a full example of creating an Annotation Extension object, adding the extension to the chart, creating an annotation circle object with attributes and adding the circle to the Annotation Object List:


SoftwareFX.ChartFX.Annotation.AnnotationX annot = new SoftwareFX.ChartFX.Annotation.AnnotationX();
chart1.getExtensions().add(annot);
AnnotationCircle circle = new AnnotationCircle();
annot.getList().add(circle);
circle.setColor(java.awt.Color.RED);
circle.setHeight(30);
circle.setWidth(30);
circle.attach(0,50);
circle.refresh();

It is also important to call the Refresh method for an object when added or any attribute of the object is modified. Due to performance reasons Chart FX does not do this automatically.

Using the Enabled property of the AnnotationX class, developers may allow or prevent users from interacting with annotation objects added to charts programmatically. By default this property is set to False. Setting the property to True permits users to change the size, color, location, etc., of annotation objects in the chart. When displaying the annotation toolbar, the Enabled property must be set to True before the annotation object is added as an extension to the chart. Please see the annotation toolbar section for more information.

Note: The AnnotationObject class supports the AllowMove and AllowModify properties that also allow and deny modification of individual annotation objects.