Annotations

Topics:

Multiple instances of two objects are all that is required to create annotations. They are the label and box drawn behind it (if any). Both the label and box have attributes associated with them. These attributes can be set using methods in Perspective for Java that are available for other chart objects (for example, setTextString(), setFillColor(), and so on)

Object IDs

The following object IDs are used to create annotations:

  • IdentObj getAnnotation(int index)
  • IdentObj getAnnotationBox(int index)

where:

index

Is a value in the range zero (0) to the maximum number of annotations set by setMaxNumAnnotations(int nMax). The default maximum number of annotations is 30.

Note that the title, subtitle and footnote objects have the same behavior as annotations. Their Object IDs are returned by the following methods:

  • IdentObj getFootnote()
  • IdentObj getFootnoteBox()
  • IdentObj getSubtitle()
  • IdentObj getSubTitleBox()
  • IdentObj getTitle()
  • IdentObj getTitleBox()

Enable Annotation

The setDisplay() method must be used to enable the annotation object:

  • setDisplay(getAnnotation(index), true);

Define Annotation Label/String

The setTextString() method can be used to define an annotation's label/string:

  • setTextString(getAnnotation(index), "string");

Set Annotation Text Color

The setFillColor() method can be used to define the color of the annotation label/string:

  • setFillColor(getAnnotation(index), new Color(0,255,0));

Note that all other fill types are also available for annotation labels (that is, gradient, texture, and so on).

Set Annotation Font Size

The normal font size methods can be used to set the font size of an annotation label.

Example:

setFontSizeAbsolute(getAnnotation(0),true);
setFontSizeInPoints(getAnnotation(0),20);

Set Annotation Location

The setRect() function can be used to specify the location of an annotation object.

Example:

setRect(getAnnotation(0),new Rectangle(-15340,11000,29850,1800)); 

Note: If you do not specify a location, the annotation text is drawn in the default location (the center of the chart) and may not be detectable. This is due to the fact that a rectangle is not internally stored for the annotation. Unless specified otherwise, it will use the default rectangle set by setRect(). It is recommended you store a rectangle location for each annotation.

Example:

setDisplay(getAnnotation(0), true); 
setTextString(getAnnotation(0), "This is a movable annotation"); 
setFillColor(getAnnotation(0), new Color(0,255,0));
setRect(getAnnotation(0),new Rectangle(-15340,11000,29850,1800)); 
setFontSizeAbsolute(getAnnotation(0),true);
setFontSizeInPoints(getAnnotation(0),20.0);
graph with annotation

Enable Annotation Box

The setDisplay() method must be used to enable the annotation box object:

  • setDisplay(getAnnotationBox(index), true);

Set Annotation Box Color

The setFillColor() method can be used to define the color of the annotation box:

  • setFillColor(getAnnotationBox(0), new Color(0,0,255));

Enable/Disable Annotation Box Border Color

The setTransparentBorderColor() method can be used to enable/disable the border color around the annotation box:

  • setTransparentBorderColor(getAnnotationBox(0), false);
  • setTransparentFillColor(getAnnotationBox(0), true);

See Beveled Borders for information about applying a border to an annotation box.

Example:

setDisplay(getAnnotation(0), true); 
setTextString(getAnnotation(0), "This is a movable annotation"); 
setFillColor(getAnnotation(0), new Color(0,255,0));
setRect(getAnnotation(0),new Rectangle(-15340,11000,29850,1800)); 
setFontSizeAbsolute(getAnnotation(0),true);
setFontSizeInPoints(getAnnotation(0),20.0);
setDisplay(getAnnotationBox(0), true); 
setFillColor(getAnnotationBox(0), new Color(0,0,255)); 
setTransparentBorderColor(getAnnotationBox(0), false); 
graph with annotation box border color

Initial/Default Annotation Box Settings

The default maximum number of annotations is 30. For this first default set of annotations, the transparent fill color is set to true and border colors are omitted for the associated annotation box:

  • setTransparentFillColor(getAnnotationBox(nnn), true);
  • setTransparentBorderColor(getAnnotationBox(nnn), true);

Maximum Number of Annotations

The following methods can be used to get/set the maximum number of annotations:

  • void setMaxNumAnnotations(int newValue);
  • int getMaxNumAnnotations();

where:

newValue

Is a value in the range 0...999.

For annotations in excess of the default (30), the setTransparentFillColor() and setTransparentBorderColor() methods should be used to set transparent fill and border colors for the associated annotation box as desired:

  • setTransparentFillColor(getAnnotationBox(nnn), true | false);
  • setTransparentBorderColor(getAnnotationBox(nnn), true | false);

WebFOCUS

Feedback