Legend & Annotations API
Legend
Set Visible
Set Position
Text size, style, font
Text Color
Legend Symbols (box, line, cross) shown in legend box
Layout (Vertical/Horizontal)
Labels Reversed Order
Legend Background Color
Legend Background Visible
Border setVisible
Legend Border Color
Annotations
Adding Annotations to Chart
Set Value
Annotation Background Color
Set Text Color
Set Text Font
Set Relative Position
Adding & Linking Annotations to Control Lines
Adding Annotation Set as Legend
Text Replacement

Legend
To manipulate, first create an ILegend object that has a handle on the chart's Legend.  Then, legend properties can be edited through methods in the ILegend.

// create an ILegend object, “hLegend”, that a handle on the chart’s legend
ILegend hLegend = chart.gethLegend();
Set Visible  
// set legend visible
hLegend.setVisible(true);
 
Set Position  
// set relative position of the legend, (rel. width, rel. height)
hLegend.setPosition(new Position(0.9f, 0.2f));

// Note: if you are getting a NullPointerException at this line when running
// your program, you need to get graphics for the chart first.  Click
// here to find out how
 

Text size, style, font  
// create an IText object, “hText” that has a handle on the Legend’s Text
IText hText = hLegend.gethText();

// setting font properties
hText.setFont( new Font("TIMES_ROMAN", Font.PLAIN, 12) );
 

Text Color  
hText.setColor( Color.blue );
 
Legend Symbols (box, line, cross) shown in legend box  
// set data point symbols drawn in the legend box
hLegend.setDrawSymbols(true);
 
Layout (Vertical/Horizontal)  
// set legend layout
hLegend.setLayout( QbChart.VERTICAL );
 
Labels Reversed Order  
// set legend title appearance to be reversed
hLegend.setLabelsReversed( true );
 
Legend Background Color  
// set legend box background properties
hLegend.setBackgroundColor( Color.gray );
 
Legend Background Visible  
hLegend.setBackgroundVisible( true );


Border setVisible

 
// set legend box border visible
hLegend.setBorderVisible(true);


Legend Border Color

 
// set legend box border color = red
hLegend.setBorderColor(Color.red);
Annotations
To insert Annotations, first create an IAnnotationSet object that has a handle on the chart's Annotations.  Then, create instance of IAnnotation through the method, newAnnotation, in the IAnnotationSet.  Finally, add this annotation by calling the addAnnotation method in the IAnnotationSet.
 
Adding Annotations to Chart
// create an IAnnotationSet object, “hAnnotation” that
// has a handle on the chart’s Annotations
IAnnotationSet hAnnotation = chart.gethAnnotations();

// create an IAnnotation object, “annot” by calling the
// “newAnnotation” method in the IAnnotationSet class
IAnnotation annot = hAnnotation.newAnnotation("Old Event");

Set Value
//replace annotation text to "New Event"
annot.setValue("New Event");
Annotation Background Color
annot.setBackgroundColor( Color.cyan );
Set Text Color
// set text color to blue
annot.setColor( Color.blue );
Set Text Font
// set font properties
annot.setFont( new Font("TIMES_ROMAN", Font.PLAIN, 12) );
Set Relative Position
// set relative position of the Annotation, (rel. width, rel. height)
annot.setRelativePosition( new Point_2D(0.85f, 0.22f) );

// Add “annot” to “hAnnotatioin”
hAnnotation.addAnnotation(annot);

Adding & Linking Annotations to Control Lines
To insert Control Lines, first create an IDataLineSet object that has a handle on the chart's DataLines.  Then, lines & their annotations can be inserted and edited through methods in the IControlLine.
// Add Annotations to an Object( in this case--a Control Line)

// create an IDataLineSet object, “hDataLines” that
// has a handle on the chart’s DataLines
IDataLineSet hDataLines = chart.gethDataLines();

// create an IControlLine object, “cLine1” by calling the
// “newControlLine” method through “hDataLines”
IControlLine cLine1 = hDataLines.newControlLine(
IControlLine.CONTROL_AVERAGE, "");

// create an IAnnotationSet object, “hAnnotation” that
// has a handle on the chart’s Annotations
IAnnotationSet hAnnotation = chart.gethAnnotations();

// create an IAnnotation object, “anno1”, by calling the
// “newAnnotation” method through the “hAnnotation” object
IAnnotation anno1 = hAnnotation.newAnnotation("Average", cLine1);

//replace text to "New Average"
annot.setValue("New Average");

// set text color to yellow
annot.setColor( Color.yellow );

// set font style properties
annot.setFont( new Font("TIMES_ROMAN", Font.PLAIN, 12) );

// add “anno1” to “cLine1”
cLine1.addAnnotation(anno1);

// add “cLine1” to the “hDataLines” object
hDataLines.add(cLine1);

Adding Annotation Set as Legend
A way to customize legends in the EspressChart API is to add customized annotations as a set.  When this is done, it would look like legends.  Symbols can be added to the annotations in the EspressChart API.
// create an IAnnotationSet object “set” that has
// a handle on the chart’s Annotations
IAnnotationSet set = chart.gethAnnotations();

// specifications for the annotations
String[] text = {"New Legend", "Hello World", "ABC", "I got It"};
int[] shape = {QbChart.PLUS, QbChart.NOSYMBOL,
QbChart.SQUARE, QbChart.DASH};
Color[] color = {Color.red, Color.black, Color.blue, Color.white};

// create an array of Annotation objects by specifying text, shape, and color
IAnnotation anno = set.newAnnotation(text, shape, color);

// add the array to the IAnnotationSet object “set”
set.addAnnotation(anno);

Text Replacement
For information on Text Replacement, please refer to Text Replacement in Axis Label API.

Please refer to QbChart, IText, ILegend, IAnnotationSet, IAnnotation, IDataLineSet, & IControlLine in EspressChart APIDocs for additional information.