InetSoft Product Information: Charts API

Polar coordinates represent data in terms of an angle and magnitude (radius). They are defined by the PolarCoord object, which accepts a RectCoord object as input. The following sections explain how to create and modify polar coordinates. They also demonstrate a common use of polar coordinates, the pie chart.

Converting Rectangular to Polar Coordinates To use polar coordinates, you first need to create a set of rectangular coordinates. Consider the script from the previous section, Rectangular Coordinates:

 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 = [["Direction", "Score"],
            [(Math.PI/2),20],
            [(Math.PI/4),30],
            [(Math.PI),35]];
 dataset = new DefaultDataSet(arr);
 graph = new EGraph();
 var elem = new PointElement("Direction", "Score");
 var xscale = new LinearScale("Direction");
 var yscale = new LinearScale("Score");
 yscale.setMin(0);
 yscale.setMax(40);
 var yaxis = new AxisSpec();
 yaxis.setGridStyle(GraphConstants.DOT_LINE);
 yscale.setAxisSpec(yaxis);
   xscale.setMin(0);
 xscale.setMax(1.95*Math.PI);
 xscale.setIncrement(Math.PI/8);
 var xaxis = new AxisSpec();
 var tspec = new TextSpec();
 tspec.setFormat(new java.text.DecimalFormat("0.0"));
 xaxis.setTextSpec(tspec);
 xaxis.setGridStyle(GraphConstants.DOT_LINE);
 xscale.setAxisSpec(xaxis);
   graph.setScale("Direction",xscale);
 graph.setScale("Score",yscale);
 var rect = new RectCoord(xscale,yscale);
 graph.setCoordinate(rect);
 graph.addElement(elem);

Note that this script explicitly creates a set of rectangular coordinates by calling the RectCoord constructor. To convert the chart to a polar coordinate system, use this RectCoord object to create a new PolarCoord object:

 var polar = new PolarCoord(rect);

Assign this new coordinate set to the chart to obtain the desired polar representation. The modified script is shown below:

 importPackage(inetsoft.graph)
 importPackage(inetsoft.graph.element)
 importPackage(inetsoft.graph.scale)
 importPackage(inetsoft.graph.aesthetic)
 importPackage(inetsoft.graph.coord)
   var arr = [["Direction", "Score"],
            [(Math.PI/2),20],
            [(Math.PI/4),30],
            [(Math.PI),35]];
 dataset = new inetsoft.graph.data.DefaultDataSet(arr);
 graph = new EGraph();
 var elem = new PointElement("Direction", "Score");
 var xscale = new LinearScale("Direction");
 var yscale = new LinearScale("Score");
 yscale.setMin(0); yscale.setMax(40);
 var yaxis = new AxisSpec();
 yaxis.setGridStyle(GraphConstants.DOT_LINE);
 yscale.setAxisSpec(yaxis);
   xscale.setMin(0);
 xscale.setMax(1.95*Math.PI);
 xscale.setIncrement(Math.PI/8);
 var xaxis = new AxisSpec();
 var tspec = new TextSpec();
 tspec.setFormat(new java.text.DecimalFormat("0.0"));
 xaxis.setTextSpec(tspec);
 xaxis.setGridStyle(GraphConstants.DOT_LINE);
 xscale.setAxisSpec(xaxis);
   graph.setScale("Direction",xscale);
 graph.setScale("Score",yscale);
 var rect = new RectCoord(xscale,yscale);
 var polar = new PolarCoord(rect);
 graph.setCoordinate(polar);
 graph.addElement(elem);
Previous: Chart API