Annotation Group

Annotation Group

The AnnotationGroup class allows you to create annotation group objects. An annotation group will consist of multiple instances of annotation objects. One advantage of working with this is that the group object exposes all common properties (AnnotationObject class), so you could change visual attributes of all of the objects in a group with just one property call. Another advantage is that when objects are grouped together, they may be rotated and moved as a group. For example, let's say you create a stick person figure using circles and line annotation objects. If each object is rotated individually, the stick figure looses its shape. Conversely, if you create a group of objects that make a stick figure and then rotate the group, all the objects will keep there shape and the stick figure will stay intact.

Creating an annotation group object is exactly like creating any other annotation object. Once the group object has been created, you may begin to add individual objects to the group. Once all the desired objects have been added to the group, the group can be added to the annotation list object. By setting attributes to the group object, all the individual objects added to the group are altered. Below is an example of creating an annotation group consisting of a circle and a balloon object:


SoftwareFX.ChartFX.Annotation.AnnotationX annot = new SoftwareFX.ChartFX.Annotation.AnnotationX();

chart1.getExtensions().add(annot);

AnnotationGroup group1 = new AnnotationGroup();
annot.getList().add(group);


AnnotationCircle circle = new AnnotationCircle();
circle.setColor(java.awt.Color.RED);
circle.setHeight(30);
circle.setWidth(30);
circle.attach(0,50);
circle.refresh();

AnnotationBalloon balloon = new AnnotationBalloon();
balloon.setHeight(100);
balloon.setWidth(100);
balloon.setText("Sample Text");
balloon.attach(100,100);

group.getList().add(circle);
group.getList().add(balloon);
circle.refresh();
balloon.refresh();
group.recalcBounds();

Recalculating the Group Object Bounds

Whenever a group is added to the annotation list, the bounds of the group object must be set. This may be done by setting the height and width of the group as well as attaching or configuring a position in the chart for the group. Instead of setting these properties manually, you can instruct Chart FX to calculate these values for you by calling the RecalcBounds method. This method should also be invoked every time an object is added to a group or when any of the objects contained in a group are resized or moved.


group.recalcBounds();