# Thread: Drawing Pie Chart in Symbian

1. Hi,
I want to show the percentage of the score as Pie Chart.
Can anyone help me in drawing pie chart in Symbian.
In some other thread, some one is telling Math::Sin() or Math::Cos() functions.
What is the relation of these functions with Pie chart ? How can I draw ?

2. Those other threads are right. Sine and cosine are trigonometric functions (http://en.wikipedia.org/wiki/Trigonometric_functions), particularly useful for coordinate geometry. And you actually do need the resulting coordinates of geometric transformations.
In short: when you want x and y to traverse around a circle with radius r, you can use
Code:
```x = r * cos (a)
y = r * sin (a)```
where a is an angle, running from 0 to 2*pi (most computing environments expect you to provide angles in radians, http://en.wikipedia.org/wiki/Radian)
For expressing 100% as a full circle
Code:
`a = p / 100 * 2 * pi = p * pi /50`
can be used, where p is a percentage.

3. Originally Posted by wizard_hu_
Those other threads are right. Sine and cosine are trigonometric functions (http://en.wikipedia.org/wiki/Trigonometric_functions), particularly useful for coordinate geometry. And you actually do need the resulting coordinates of geometric transformations.
In short: when you want x and y to traverse around a circle with radius r, you can use
Code:
```x = r * cos (a)
y = r * sin (a)```
where a is an angle, running from 0 to 2*pi (most computing environments expect you to provide angles in radians, http://en.wikipedia.org/wiki/Radian)
For expressing 100% as a full circle
Code:
`a = p / 100 * 2 * pi = p * pi /50`
can be used, where p is a percentage.

but its not displaying with respect to percentage given.
see my code:
Code:
```TInt p = 50; // percentage
TReal src  = (p * 360) / 100;
RDebug::Print(_L("---> src = %f"), src);
TInt r = 155;
TReal result;

Math::Cos(result, src);
TInt x = r * result;
RDebug::Print(_L("result X = %d"), result);
RDebug::Print(_L("x = %d"), x);

Math::Sin (result, src);
TInt y = r * result;
RDebug::Print(_L("result Y = %d"), result);
RDebug::Print(_L("y = %d"), y);

// draw a pie slice centered in the rectangle
gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
gc.SetBrushColor(KRgbRed);
TRect ellipseRect=Rect(); // for arcs and ellipse
ellipseRect.SetWidth(250);
ellipseRect.SetHeight(250);
ellipseRect.Shrink(10,10); // set size so inside the border rectangle

//TRect rect;
TPoint screenCenterPoint=ellipseRect.Center(); // the center of the screen
// set up a pair of construction points for arc and pie slice drawing
TPoint constructionPoint1(210,125); // outside the construction ellipse
TPoint constructionPoint2(y,x); // inside the construction ellipse
TSize size(250,250);
gc.DrawRoundRect(ellipseRect,size);
//gc.DrawPie(ellipseRect,constructionPoint1,constructionPoint2);
// draw the other portion of the elliptical disc
gc.SetBrushColor(KRgbGreen);
gc.DrawPie(ellipseRect,constructionPoint1,constructionPoint2);```

4. Originally Posted by sunitha.m13
see my code:
Code:
```TInt p = 50; // percentage
TReal src  = (p * 360) / 100;```
I see it. Guess why I wrote "a = p / 100 * 2 * pi = p * pi /50".
Computing languages measure angles in radians ("RAD" mode on a scientific calculator), while your code does that in degrees ("DEG" mode).
2*pi (~6.2832) radians are 360 degrees, a full circle. Replace 360 with 2*pi (2*KPi in Symbian C++), and it will be better.

5. Originally Posted by wizard_hu_
I see it. Guess why I wrote "a = p / 100 * 2 * pi = p * pi /50".
Computing languages measure angles in radians ("RAD" mode on a scientific calculator), while your code does that in degrees ("DEG" mode).
2*pi (~6.2832) radians are 360 degrees, a full circle. Replace 360 with 2*pi (2*KPi in Symbian C++), and it will be better.
I have changed 360 to 2*KPi, but still no change. Its not drawing correctly.
I guess I need to change the logic behind the constructionPoint1 & constructionPoint2

TPoint constructionPoint1(210,125); // outside the construction ellipse
TPoint constructionPoint2(x,y); // inside the construction ellipse
gc.DrawPie(ellipseRect,constructionPoint1,constructionPoint2);

6. Those points should be absolute coordinates, so add a
Code:
`constructionPoint2+=screenCenterPoint;`
, and it is going to get much better. After that try with various p-s (0, 25, 50, 75), and you will see that constructionPoint1 needs to be re-calculated, because it represents something else than 0% (25% or 75%, I have not checked exactly, but it is a quarter pie to one direction).

7. Yes...its drawing as expected but in reverse direction.
Can you tell me how to change the direction of drawing ?

I tried to give negative sign for the co-ordinates, but entire calculation goes wrong with that.

8. invert the angle

look at the angle from 0 to 360 degrees and then think what you have to add or subtract.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.