|
AngularAxis.addZone bug? |
Posted by Serge on Apr-15-2011 07:48 |
|
Hi,
The docs say that the 'startRadius' and 'endRadius' parameters of AngularAxis.addZone method are in pixels.
This doesn't seem to be true and one has to supply values in the data range instead.
For example, if data on my polar chart is in range [0 - 10000] (so the radial axis displays 10000 as the max label) then I have to pass startRadius=5000 and endRadius=10000, if I wanted to highlight the upper half of a sector, and not 200 and 400 (chart radius is 400 pixels).
The actual problem is that the parameters are declared as 'int'. So if my data were in range [0 - 0.1] I wouldn't be able to defined a zone at all!
Another problem with this method is that it draws the zone (sector) *outside* the polar plot area if endRadius > max value. |
Re: AngularAxis.addZone bug? |
Posted by Peter Kwan on Apr-15-2011 15:06 |
|
Hi Serge,
You are correct that the radii in addZone are in fact in radial axis coordinates, not in pixels.
I do not remember the original intention of the addZone API, as it has been around for many years. I notice that even our own sample code (like the "Simple Rose Chart" sample code) relies on the fact that the radius are in radial coordinates, and there should be a lot of people relying on this fact. So we cannot change the behaviour now for compatibility reasons, and we must consider that the error is in the documentation. It also means you can safely assume that the radius is in radial coordinate and it would not change in the future.
For the radius, I think it is in "double", not in "int". So even if your axis is from 0 to 0.1, you can still use addZone by using floating point numbers as the radii. For example, in our own sample code "Simple Rose Chart", we use floating point numbers as radii, and it works correctly.
If you add a zone that is outside the axis range, ChartDirector will draw the zone outside the axis range. If you do not want the zone to be outside the axis range, you may consider not to add the zone outside the axis range. For example, you may limit the zone radii to the axis range. If you are not sure what is the axis range (eg. because the radiaAxis is auto-scaled), you may use the following method to query ChartDirector. (The following is in Java.)
... add data to the chart, and configure the chart size ...
c.layout(); //auto-scale the axis
double maxRadius = c.radialAxis().getMaxValue();
double minRadius = c.radialAxis().setMinValue();
//make sure the innerRadius and outerRadius is bound by the axis range
c.angularAxis().addZone(0, 90, Math.max(myInnerRadius, minRadius), Math.min(myOuterRadius, maxRadius));
Hope this can help.
Regards
Peter Kwan |
Re: AngularAxis.addZone bug? |
Posted by Serge on Apr-17-2011 19:56 |
|
Hi Peter,
Thank you for the very detailed answer.
I agree that 'pixels' and 'int' are errors in the help file. And I have switched my code to use radial coordinates and limit the zone by getMaxValue().
Serge |
|