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

Message ListMessage List     Post MessagePost Message

  PolarChart issues
Posted by Itzik on Mar-17-2019 22:25
I'm using PolarChart Object on C# Winforms, And there are some issues that I need help with.

Legend Box - How can I add a title at the top of the box.
I tried to use the  SetText()  method And I did not notice any changes in view.

Legend Box - Is it possible to place the legend box on the center-right side of the polar chart programmatically, so  it will always be aligned.
I used the method setAlignment() and also did not notice any changes in view.

How can I add the percentage sign [%]to the numbers that indicate the display value (see details in attached picture)

How to define the graph to fill the window dynamically? So the graph can be resize dynamically and fit the winform size exactly.
I tried to use the property .Dock = DockStyle.Fill, and it does not seem to work as expected.

Best Regards, Itzik
Wind Rose.JPG

  Re: PolarChart issues
Posted by Peter Kwan on Mar-19-2019 01:19
Hi Itzik,

1. The legend box is added to the coordinates provided by your code. An example is like:

LegendBox legendBox = c.addLegend(320, 60);

The above means the top-left corner of the legend box is at (320, 60).

You can add some text above the legend box using BaseChart.addText. For example:

c.addText(320, 60, "Legend", "Arial Bold", 12, 0x000000, Chart.BottomLeft);

The Chart.BottomLeft above means the point (320, 60) refers to the bottom-left of the text. That means the text is above the (320, 60) point, and so is above the legend box.

2. You can determine a point to the right of your polar chart drawing, so that it becomes the center-left of the legend box. For example:

// (cx, cy) = center of the polar chart. radius = radius of the polar chart
LegendBox b = c.addLegend(cx + radius + 30, cy);

The above means that the point (cx + radius + 30, cy)   (which is a point to the right of the polar chart) is the center-left of the legend box. That means the legend box is to the right side of that point, and is vertically center aligned to that point.

With the above, the top-side of the legend is not fixed, but changes according to data. (In (1) above, the top side is fixed at y = 60.) To add text above the legend box, you need to use the following sequence:

- Create the chart as usual with the legend box

- Call "c.layoutLegend();". This tells ChartDirector all data have been entered and it can start filling the legend box to determine its height and position.

- c.addText(legendBox.getLeftX(), legendBox.getTopY(), "Legend", "Arial Bold", 12, 0x000000, Chart.BottomLeft);

3. You can use Axis.setLabelFormat. For example:

// display the value, followed by %

4. The WinChartViewer control is similar to a .NET Picture control in "Standard" size mode. When you resize it, the control becomes larger, but the image inside the control does not unchanged. So it just occupies more empty space.

You can configure the WinChartViewer to act like a Picture control in "StretchImage" size mode. When you resize it, the image resizes but can become "blurry" if you resize it up and it does not maintain aspect ratio. For example, if the original image is 500 x 300, and you resize it to 500 x 600, then the text will be of the same width, but the text height is doubled, making the text looks strange. A circle will become an ellipse as it is stretched vertically but not horizontally.

I think your intention is to redraw the chart at a size that best fit the window. Some of the sample code in ChartDirector demonstrate a common method to do this. Two examples are:

(a) The Real Time Sweep Chart sample code in the LIbrary section of our web site:

In the above sample code, the chart is created as the same size as the WinChartViewer control, which is docked to the Form using Fill. The code is like:

XYChart c = new XYChart(Math.Max(300, viewer.Width), Math.Max(150, viewer.Height));

For your case, please change the above to a PolarChart. The Math.Max is to ensure the minimum size is 300 x 300 even when the Window is resized to very small.

The chart is redrawn when the winChartViewer1_SizeChanged event occurs, so the chart keeps up with the control size.

(b) Another example demonstrates how to make resizable content:

Your code can parameterized all sizes starting from a reference size, which can be based on the PolarChart width or height or some other formula:

int size = ... some size ...;
int radius = size / 3;
int cx = radius + size / 20;
int cy = cx;
int fontSize = size / 50;

To come up with ideal ratios, please create a chart with a fixed size (eg. say 500) and layout to your satisfaction. You can then use that chart to determine the various ratios.

Peter Kwan

  Re: PolarChart issues
Posted by Anto on Oct-18-2022 17:38
Can u share complete source?

  Re: PolarChart issues
Posted by Peter Kwan on Oct-18-2022 23:32
Hi Anto,

The chart in this thread is modified from the "Stacked Rose Chart" sample code included in the ChartDirector download. The following is the .NET version of the sample code. The sample code is also included in other programming language editions of ChartDirector.

Best Regards
Peter Kwan