Drawing Pie Chart in Symbian
Hi,
I want to show the percentage of the score as [B]Pie Chart[/B].
Can anyone help me in drawing pie chart in Symbian.
In some other thread, some one is telling [B]Math::Sin()[/B] or [B]Math::Cos()[/B] functions.
What is the relation of these functions with Pie chart ? How can I draw ?
Re: Drawing Pie Chart in Symbian
Those other threads are right. Sine and cosine are trigonometric functions ([url]http://en.wikipedia.org/wiki/Trigonometric_functions[/url]), 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)[/CODE]where a is an angle, running from 0 to 2*pi (most computing environments expect you to provide angles in radians, [url]http://en.wikipedia.org/wiki/Radian[/url])
For expressing 100% as a full circle[CODE]a = p / 100 * 2 * pi = p * pi /50[/CODE]can be used, where p is a percentage.
Re: Drawing Pie Chart in Symbian
[QUOTE=wizard_hu_;735118]Those other threads are right. Sine and cosine are trigonometric functions ([url]http://en.wikipedia.org/wiki/Trigonometric_functions[/url]), 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)[/CODE]where a is an angle, running from 0 to 2*pi (most computing environments expect you to provide angles in radians, [url]http://en.wikipedia.org/wiki/Radian[/url])
For expressing 100% as a full circle[CODE]a = p / 100 * 2 * pi = p * pi /50[/CODE]can be used, where p is a percentage.[/QUOTE]
Thanks for the reply....
but its not displaying with respect to percentage given.
see my code:
[CODE][B]TInt p = 50; // percentage[/B]
TReal src = (p * 360) / 100;
RDebug::Print(_L("---> src = %f"), src);
TInt r = 155;
TReal result;
Math::Cos([B]result[/B], src);
[B] TInt x = r * result;[/B]
RDebug::Print(_L("result X = %d"), result);
RDebug::Print(_L("x = %d"), x);
Math::Sin ([B]result[/B], src);
[B]TInt y = r * result;[/B]
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);[/CODE]
Re: Drawing Pie Chart in Symbian
[QUOTE=sunitha.m13;738577]see my code:
[CODE][B]TInt p = 50; // percentage[/B]
TReal src = (p * 360) / 100;[/CODE][/QUOTE]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.
Re: Drawing Pie Chart in Symbian
[QUOTE=wizard_hu_;738598]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.[/QUOTE]
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 [COLOR="DarkGreen"]constructionPoint1 [/COLOR]& [COLOR="DarkGreen"]constructionPoint2[/COLOR]
TPoint [B]constructionPoint1(210,125)[/B]; // outside the construction ellipse
TPoint [B]constructionPoint2(x,y)[/B]; // inside the construction ellipse
gc.DrawPie(ellipseRect,constructionPoint1,constructionPoint2);
Re: Drawing Pie Chart in Symbian
Those points should be absolute coordinates, so add a[CODE]constructionPoint2+=screenCenterPoint;[/CODE], 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).
Re: Drawing Pie Chart in Symbian
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.
Re: Drawing Pie Chart in Symbian
invert the angle
look at the angle from 0 to 360 degrees and then think what you have to add or subtract.