InetSoft Product Information: Dashboarding API

When you assign a VisualFrame to a chart element to visually code data, a corresponding legend is created automatically. You can change the appearance of this legend by editing the VisualFrame's LegendSpec.

Consider the following script:

 importPackage(inetsoft.graph)
 importPackage(inetsoft.graph.element)
 importPackage(inetsoft.graph.scale)
 importPackage(inetsoft.graph.aesthetic)
 importPackage(inetsoft.graph.data)
   var arr = [["State", "Quantity"], ["NJ",200], ["NY",300]];
 dataset = new DefaultDataSet(arr); graph = new EGraph();
 var elem = new IntervalElement("State", "Quantity");
 var frame = new CategoricalColorFrame("State");
 elem.setColorFrame(frame);
 graph.addElement(elem);

This creates a basic bar chart displaying the dimensions 'State' and 'Quantity'. In this script, a CategoricalColorFrame distinguishes the different states by color. Follow the steps below to experiment with modifying the chart's legend:

  1. Change the legend border to a blue dotted line. To do this, create a LegendSpec object and assign it to the ColorFrame.
 var legend = new LegendSpec();
 legend.setBorder(GraphConstants.DOT_LINE);
 legend.setBorderColor(java.awt.Color(0x0000ff));
 frame.setLegendSpec(legend); 
  1. Change the legend title to say simply 'State', and make the text bold. To do this, create a TextSpec object and assign it to the LegendSpec.
 var tspec = new TextSpec();
 tspec.setFont(java.awt.Font('Dialog',
               java.awt.Font.BOLD, 14));
 legend.setTitleTextSpec(tspec);
 legend.setTitle('State'); 
  1. Change the text inside the legend to display the full state names. To do this, create a TextFrame object and assign it to the LegendSpec.
 var tframe = new DefaultTextFrame();
 tframe.setText('NJ','New Jersey');
 tframe.setText('NY','New York');
 legend.setTextFrame(tframe); 
  1. Place the legend above the chart. Use the Graph's legendLayout property to do this.
graph.setLegendLayout(GraphConstants.TOP);
demo
Read how InetSoft saves money and resources with deployment flexibility.

The complete script is shown below.

 importPackage(inetsoft.graph)
 importPackage(inetsoft.graph.element)
 importPackage(inetsoft.graph.scale)
 importPackage(inetsoft.graph.aesthetic)
 importPackage(inetsoft.graph.data)
   var arr = [["State", "Quantity"], ["NJ",200], ["NY",300]];
 dataset = new DefaultDataSet(arr);
 graph = new EGraph();
 var elem = new IntervalElement("State", "Quantity");
 var frame = new CategoricalColorFrame("State");
 elem.setColorFrame(frame);
   var legend = new LegendSpec();
 legend.setBorder(GraphConstants.DOT_LINE);
 legend.setBorderColor(java.awt.Color(0x0000ff));
 frame.setLegendSpec(legend);
 var tspec = new TextSpec();
 tspec.setFont(java.awt.Font('Dialog',
               java.awt.Font.BOLD, 14));
 legend.setTitleTextSpec(tspec);
 legend.setTitle('State');
 var tframe = new DefaultTextFrame();
 tframe.setText('NJ','New Jersey');
 tframe.setText('NY','New York');
 legend.setTextFrame(tframe);
 graph.setLegendLayout(GraphConstants.TOP);
   graph.addElement(elem); 
Read the top 10 reasons for selecting InetSoft as your BI partner.