×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Bangalore, India
    Posts
    454

    Drawing Pie Chart in Symbian

    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 ?
    Regards,
    Sunitha.M

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,745

    Re: Drawing Pie Chart in Symbian

    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. #3
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Bangalore, India
    Posts
    454

    Re: Drawing Pie Chart in Symbian

    Quote Originally Posted by wizard_hu_ View Post
    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.
    Thanks for the reply....

    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);
    Last edited by sunitha.m13; 2010-05-20 at 10:03.
    Regards,
    Sunitha.M

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,745

    Re: Drawing Pie Chart in Symbian

    Quote Originally Posted by sunitha.m13 View Post
    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. #5
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Bangalore, India
    Posts
    454

    Re: Drawing Pie Chart in Symbian

    Quote Originally Posted by wizard_hu_ View Post
    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);
    Regards,
    Sunitha.M

  6. #6
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,745

    Re: Drawing Pie Chart in Symbian

    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. #7
    Regular Contributor
    Join Date
    Aug 2009
    Location
    Bangalore, India
    Posts
    454

    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.
    Regards,
    Sunitha.M

  8. #8
    Super Contributor
    Join Date
    Jul 2008
    Posts
    2,020

    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.
    The lines above are the best I have to offer.If anyone of you is of more advanced knowledge, I ask for your patience and understanding! - unknown arab poet
    http://www.tamoggemon.com - Symbian blog - Windows Phone blog
    My other blogs:
    webOS blog iPhone blog BlackBerry blog Samsung bada blog Android blog

Similar Threads

  1. A little survey regarding Java vs Symbian C++
    By Olnex in forum Mobile Java General
    Replies: 0
    Last Post: 2006-11-01, 09:00
  2. Question regarding Java vs Symbian C++
    By Olnex in forum Mobile Java General
    Replies: 5
    Last Post: 2006-09-27, 23:53
  3. Replies: 1
    Last Post: 2006-09-27, 14:19
  4. Replies: 2
    Last Post: 2003-08-19, 16:39
  5. setting of Series 60 MIDP SDK for Symbian OS version 1.2 for networking
    By servigo in forum Mobile Java Networking & Messaging & Security
    Replies: 2
    Last Post: 2003-07-31, 07:47

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×