 ChartDirector Support Forum Home Search PolarLineLayer and setAngles
Posted by Mark Chidwick on Jan-16-2021 05:31
I would like to create a polar chart with 5 axes.  I set up the chart as

PolarChart c = new PolarChart(xs, ys, ChartPanel.chartBackground, 0x000000, 1);

and then the axis as

c.angularAxis().setLabels(labels);

where labels is an array of String.

I then set up the plot area
c.setPlotArea(xo, yo, r, 0xffffff);
c.setGridStyle(false);

and then the angles to match the axes
double[] angles = new double[axis.size()];
for (int i = 0; i < angles.length; i++) {
angles[i] = i * 360.0 / angles.length;
}

Finally, I add the line layer
PolarLineLayer l = c.addLineLayer(data, color, "name of line");
l.setAngles(angles);
l.setLineWidth(2);
l.setDataSymbol(Chart.CircleSymbol, 6);
l.setCloseLoop(true);

In this case, I have angles
(0, 72, 144, 216, 288)

and data
(0, 10, 20, 30, 40)

What is plotted is
(0, 0) connected to (144, 10) connected to (288, 20) then (72, 30) then (216, 40)

It seems that it is connecting every other angle to the data.

Any thoughts??? Re: PolarLineLayer and setAngles
Posted by Peter Kwan on Jan-16-2021 15:04
Hi Mark,

The "l.setAngles(angles);" and the "angles" variable are not necessary. Removing them should solve the problem.

The line:

c.angularAxis().setLabels(labels);

means the angularAxis will have 5 labels, and their angular coordinates are their array index 0, 1, 2, 3, 4, which distributed evenly along the circle. The angularAxis does not automatically use degrees as the unit. If you want the angular coordinates to be from 0 to 360, you would need to use c.angularAxis().setLinearScale2(0, 360, labels);.

Also, for the PolarLayer, if you do not provide the angular coordinates, it will be the array index of the data (0, 1, 2, 3, 4, 5) as the coordinates. That means the labels and data will automatically match.

The above behaviour is the same for XYCharts too. If no x-coordinates are provided, the array index is the x-coordinate, so multiple arrays will automatically match each others.

Hope this can help.

Regards
Peter Kwan Re: PolarLineLayer and setAngles
Posted by Mark Chidwick on Jan-17-2021 02:33
Peter

Thanks for such a quick response!!  Works like a charm.  Removing the setAngles() was the trick.

Many thanks!