InetSoft Product Information: Flash Chart API

To create a pie chart from this data, just convert the chart to a stacked bar, and then convert to polar coordinates. Follow the steps below:

  1. Instead of using different X-axis positions to distinguish the 'State' data, distinguish the states using a ColorFrame object. (Note that a 'null' value is assigned for the (unused) X-dimension when creating the IntervalElement and RectCoord objects)
 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", "Revenue"], ["CA", 200],
            ["NY",300],["PA",150]]; dataset = new DefaultDataSet(arr);
 graph = new EGraph(); var elem = new IntervalElement(null,"Revenue");
 var xscale = new CategoricalScale("State") var yscale = new LinearScale("Revenue");
 var rect = new RectCoord(null, yscale);
 var cframe = new CategoricalColorFrame("State");
 elem.setColorFrame(cframe);
 graph.setCoordinate(rect);
 graph.addElement(elem);
  1. Convert the chart into a stacked bar chart with just one bar by using the GraphElement's collisionModifier property. Create a StackRange object to make sure there is enough room for the stacked elements.
elem.setCollisionModifier(GraphElement.STACK_SYMMETRIC); yscale.setScaleRange(new StackRange());
  1. Create polar coordinates from the existing rectangular coordinates. By default, this maps the non-null coordinate (Y-axis) to the polar coordinate's magnitude dimension. Specify that it should be mapped to the angle dimension instead.
var polar = new PolarCoord(rect);

polar.setType(PolarCoord.THETA);
  1. Use the Chart's setCoordinate() method to apply the new polar coordinates.
graph.setCoordinate(polar);
  1. Remove the axis lines and labels. To do this, create an AxisSpec object, and assign it to the Scale.
var yspec = new AxisSpec();
yspec.setLabelVisible(false);
yspec.setLineVisible(false);
yspec.setTickVisible(false);
yscale.setAxisSpec(yspec);
  1. Add the state names to the individual slices and hide the legend. To do this, create a new TextFrame object based on the “State” field, and assign it to the GraphElement. To hide the legend, create a new LegendSpec object, and assign it to the ColorFrame.
var tframe = new DefaultTextFrame("State");
elem.setTextFrame(tframe);
var legend = new LegendSpec();
legend.setVisible(false);
cframe.setLegendSpec(legend);
  1. Explode the slices for better appearance.
elem.setHint(GraphElement.HINT_EXPLODED,'true');

The final script for the pie chart 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.data)
 
var arr = [["State", "Revenue"], ["CA", 200],
           ["NY",300],["PA",150]];
dataset = new DefaultDataSet(arr);
graph = new EGraph();
var elem = new IntervalElement(null,"Revenue");
var xscale = new CategoricalScale("State")
var yscale = new LinearScale("Revenue");
var rect = new RectCoord(null, yscale);
var cframe = new CategoricalColorFrame("State");
elem.setColorFrame(cframe);
elem.setCollisionModifier(GraphElement.STACK_SYMMETRIC);
yscale.setScaleRange(new StackRange());
var polar = new PolarCoord(rect);
polar.setType(PolarCoord.THETA);
var yspec = new AxisSpec();
yspec.setLabelVisible(false);
yspec.setLineVisible(false);
yspec.setTickVisible(false);
yscale.setAxisSpec(yspec);
var tframe = new DefaultTextFrame("State");
elem.setTextFrame(tframe);
var legend = new LegendSpec();
legend.setVisible(false);
cframe.setLegendSpec(legend);
elem.setHint(GraphElement.HINT_EXPLODED,'true');
graph.setCoordinate(polar);
graph.addElement(elem);

Previous: Charting API
Next: Graph API