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:

 

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 = [["Direction", "Score"],[(Math.PI/2),20],[(Math.PI/4),30],[(Math.PI),35]];

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(Chart.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(Chart.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:

 

dataset = [["Direction", "Score"],[(Math.PI/2),20],[(Math.PI/4),30],[(Math.PI),35]];

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(Chart.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(Chart.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);

By default, the rectangular coordinate's X-axis is mapped to the polar coordinate's angle, and the rectangular coordinate's Y-axis is mapped to the polar coordinate's magnitude (radius). To reverse a mapping, use the Coordinate object's transpose() method.

<< CT.12.2 Polar Coordinates © 1996-2013 InetSoft Technology Corporation (v11.5) Tailoring a Coordinate Mapping >>