CT.15 Adding Decorative Elements

To draw decorative elements (lines, shapes, text, etc.) on the chart, use a GraphForm object. Consider the following example:

Note: Script that modifies 'graph' should be placed at the element level. See Adding Element-Level Script in Report Scripting and Adding Component Script in Dashboard Scripting for more information.

dataset = [["State", "Quantity"],["NJ", 200],["NY", 300], ["PA", 370],["CT", 75]];

graph = new EGraph();

var elem = new IntervalElement("State", "Quantity");

graph.addElement(elem);

 

This generates a basic bar chart with quantities for four different states. To add a small note indicating that the lowest value was due to an inventory problem, follow the steps below.

1. Create a new LineForm object, and specify location values to point at the 'CT' bar.

var lineform = new LineForm();

lineform.addValues([['CT', 150],['CT', 100]]);

2. Set the line color to red, and draw an arrow at the end.

lineform.setColor(java.awt.Color(0xff0000));

lineform.setEndArrow(true);

3. Create a new LabelForm object, and specify location values to position it above the 'CT' bar.

var labelform = new LabelForm();

labelform.setValues(['CT', 150]);

4. Set the label contents, set the text color to red, and center-align. To set the text color, create a new TextSpec object and assign it to the LabelForm.

var labelSpec = new TextSpec();

labelSpec.setColor(java.awt.Color(0xff0000));

labelform.setTextSpec(labelSpec);

labelform.setLabel("Note: Low\nInventory");

labelform.setAlignmentX(GraphConstants.CENTER_ALIGNMENT);

5. Assign the LineForm and LabelForm objects to the Chart object.

graph.addForm(lineform);

graph.addForm(labelform);

 

The final script is shown below.

dataset = [["State", "Quantity"],["NJ", 200],["NY", 300],["PA", 370],["CT", 75]];

graph = new EGraph();

var elem = new IntervalElement("State", "Quantity");

var lineform = new LineForm();

lineform.addValues([['CT', 150],['CT', 100]]);

lineform.setColor(java.awt.Color(0xff0000));

lineform.setEndArrow(true);

var labelform = new LabelForm();

labelform.setValues(['CT', 150]);

var labelSpec = new TextSpec();

labelSpec.setColor(java.awt.Color(0xff0000));

labelform.setTextSpec(labelSpec);

labelform.setLabel("Note: Low\nInventory");

labelform.setAlignmentX(GraphConstants.CENTER_ALIGNMENT);

graph.addForm(lineform);

graph.addForm(labelform);

graph.addElement(elem);

 

<< CT.14 Representing Multiple Measures © 1996-2013 InetSoft Technology Corporation (v11.4) Appendix CR: Chart Script Reference >>