Adding Annotations to ChartText Replacement
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
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();
// 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
// setting font properties
hText.setFont( new Font("TIMES_ROMAN", Font.PLAIN, 12) );
Text Replacement
Adding Annotations to Chart// create an IAnnotationSet object, “hAnnotation” thatSet Value
// 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");//replace annotation text to "New Event"Annotation Background Color
annot.setValue("New Event");annot.setBackgroundColor( Color.cyan );Set Text Color// set text color to blueSet Text Font
annot.setColor( Color.blue );// set font propertiesSet Relative Position
annot.setFont( new Font("TIMES_ROMAN", Font.PLAIN, 12) );// set relative position of the Annotation, (rel. width, rel. height)Adding & Linking Annotations to Control Lines
annot.setRelativePosition( new Point_2D(0.85f, 0.22f) );// Add “annot” to “hAnnotatioin”
hAnnotation.addAnnotation(annot);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)Adding Annotation Set as Legend// 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);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);
Please refer to
QbChart,
IText,
ILegend,
IAnnotationSet,
IAnnotation,
IDataLineSet,
& IControlLine
in EspressChart APIDocs for additional information.