InetSoft Product Information: Chart Design

The example below illustrates how a developer can use InetSoft's API to control design elements of a chart design in a programmatic way. This degree of control makes InetSoft chart generator a good option for embedding into a service providers own solution.

Request a Demo
Register for Pricing
#1 Ranking: Read how InetSoft was rated #1 for user adoption in G2's user survey-based index Read More

To draw decorative elements (lines, shapes, text, etc.) on the chart, use a GraphForm object. Consider the following example (Note: Report script that modifies 'graph' should be placed at the element level. See Adding Element-Level Script):

importPackage(inetsoft.graph)
importPackage(inetsoft.graph.element)
importPackage(inetsoft.graph.scale)
importPackage(inetsoft.graph.aesthetic)
importPackage(inetsoft.graph.coord)
importPackage(inetsoft.graph.data)
 
var arr = [["State", "Quantity"], ["NJ", 200],
      ["NY", 300], ["PA", 370], ["CT", 75]];
dataset = new DefaultDataSet(arr);
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]]);
  1. Set the line color to red, and draw an arrow at the end.
 lineform.setColor(java.awt.Color(0xff0000));
 lineform.setEndArrow(true);
  1. Create a new LabelForm object, and specify location values to position it above the 'CT' bar.
 var labelform = new LabelForm();
 labelform.setValues(['CT', 150]);
  1. 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);
  1. Assign the LineForm and LabelForm objects to the Chart object.
 graph.addForm(lineform);
 graph.addForm(labelform);

The final script is shown below.

 importPackage(inetsoft.graph)
 importPackage(inetsoft.graph.element)
 importPackage(inetsoft.graph.scale)
 importPackage(inetsoft.graph.aesthetic)
 importPackage(inetsoft.graph.coord)
 importPackage(inetsoft.graph.guide)
 importPackage(inetsoft.graph.guide.form)
 importPackage(inetsoft.graph.data)

 var arr = [["State", "Quantity"], ["NJ", 200],
 ["NY", 300], ["PA", 370], ["CT", 75]];
 dataset = new DefaultDataSet(arr);
 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); 
Previous: Scorecard Measures