ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  How to autosizing polar charts
Posted by Eric de Ruiter on Jan-11-2017 23:20
Hi,

For most of our charts we can easily autosize the chart if the axis labels grow to big (by using axis->getThickness()) however for the angular axis of polar charts there is no such method (as the angular axis is not derived from Axis).

Is there another way to know how far the labels extend from the chart? I would like to know how much extra horizontal and vertical space (besides the specified radius) is needed to draw the angular labels.

Kind regards,

  Eric de Ruiter

  Re: How to autosizing polar charts
Posted by Peter Kwan on Jan-12-2017 00:59
Hi Eric,

If you know what are text in the angular labels, you can create a dummy text box just to measure their width and height. It is like (in C#):

// Create a dummy text box
ChartDirector.TextBox measurer = c.addText(-9999, -9999, "", "arial.ttf", 10);

// Set some text in the text box, and it would report the width and height
measurer.setText(myLabelText);
int width = measurer.getWidth();
int height = measurer.getHeight();

For the polar chart, if you are only adjusting the radius to fit the text, but not moving the center to fit the text, then your code will known what is the distance between the center and the edge of the chart. Assuming the text is at an angle t from the vertical line, the maximum radius that can be used width overflowing horizontally must be

r = (chart_width / 2 - width_of_text) / Math.Sin(t);

(The above assume the center is at the center of the chart. The angle t is in radians and must be non-zero. The zero angle does not need to consider.)

Your code can iterate all the labels to see what is the maximum radius allowed, and use the minimum of those radii.

For the vertical height, you may use similar method, or you may just compute them using the font height, as the height is not dependent on the amount of text, but the number of lines in the text.

Regards
Peter Kwan