×

Discussion Board

Results 1 to 15 of 15
  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    62

    Question Drawing a pie chart on a Form

    Hi everyone,

    I found a tutorial online on how to draw a pie chart in Java ME: http://www.java2s.com/Tutorial/Java/...E/Piechart.htm

    The problem is that I want to add a pie chart to a Form (so I can add text below the chart explaining what it means etc.). The implementation in this tutorial makes the pie chart its own Displayable type so I can't add it to a Form.

    Without using 3rd party libraries, is there a solution to this? I'm using the LCDUI API for my user interface.

    Thanks in advance!

  2. #2
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Drawing a pie chart on a Form

    Not really an expert on the subject matter, anyway, I suppose you could add custom item to the form.

    At least One example doing so could be found from our wiki: http://www.developer.nokia.com/Commu...orm_in_Java_ME

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    62

    Re: Drawing a pie chart on a Form

    Thanks symbianyucca, this works great. I followed a simpler example I found here: http://www.java2s.com/Tutorial/Java/...CustomItem.htm

  4. #4
    Nokia Developer Moderator
    Join Date
    Mar 2003
    Location
    Lempäälä/Finland
    Posts
    29,166

    Re: Drawing a pie chart on a Form

    Good to hear that you got it working, and if you have time, you could always make a small, quick & simple Wiki page, so anybody else needing it could utilize it next time.

  5. #5
    Registered User
    Join Date
    Aug 2013
    Posts
    5

    Exclamation problem with pie chart in a specefic form

    hello,
    i'm developping a j2ME app i have several forms , i want to draw a pie chart in a specific form (when i press on OK command, i want to see the pie chart)
    please help it's very very very urgent
    this is the pie chart code it's working but when i try to add it to my form through a command it's dosen't show anything:
    public class PieChartMIDlet extends MIDlet implements CommandListener {
    private Command exitCommand;

    public void startApp() {
    Display display = Display.getDisplay(this);

    int[] data = { 10, 20, 30, 40, 20 };
    Displayable d = new PieChartCanvas(data);

    exitCommand = new Command("exit", Command.EXIT, 1);

    d.addCommand(exitCommand);
    d.setCommandListener(this);

    display.setCurrent(d);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable s) {
    notifyDestroyed();
    }

    class PieChartCanvas extends Canvas {
    int[] data;

    int colors[] = { 0xFF0000, 0xA9E969, 0x00FFFF, 0xC675EC, 0x008800, 0x00C400 };

    public PieChartCanvas(int[] data) {
    this.data = data;
    }

    public void paint(Graphics g) {
    int width = this.getWidth();
    int height = this.getHeight();

    g.setColor(255, 255, 255);
    g.fillRect(0, 0, width, height);

    int sum = 0;
    for (int i = 0; i < data.length; i++) {
    sum += data[i];
    }
    int deltaAngle = 360 * 100 / sum / 100;
    int x = 4;
    int y = 4;
    int diameter;

    if (width > height)
    diameter = height - y * 2;
    else
    diameter = width - x * 2;

    int startAngle = 0;

    for (int i = 0; i < data.length; i++) {
    g.setColor(colors[i]);
    g.fillArc(x, y, diameter, diameter, startAngle, deltaAngle * data[i]);
    startAngle += deltaAngle * data[i];
    }
    }
    }

  6. #6
    Registered User
    Join Date
    Aug 2013
    Posts
    5

    Re: Drawing a pie chart on a Form

    please Infms, i'm facing the same problem, can you tell me how did you fix it exactly thanks for advance

  7. #7
    Registered User
    Join Date
    Jan 2009
    Location
    Melbourne, Australia
    Posts
    2,571

    Re: problem with pie chart in a specefic form

    Please use the platform specific discussion boards - these have more "expert" eyes working on them. I have moved this.

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: problem with pie chart in a specefic form

    the quick answer would be :

    1. Convert your pie chart into a LWUIT component.
    2. Make a new form add the PieChart into the form.
    3. call form.show() on your command.

    Now how to do 1.

    Make a class PieChart extend it from Component/Container override the paint method and place your pie chart drawing code there also you need to override couple of more methods to get a perfect component !!

    Regards,

  9. #9
    Registered User
    Join Date
    Aug 2013
    Posts
    5

    Re: problem with pie chart in a specefic form

    thanks for your reply, but it's impossible to convert my pie chart into a LWUIT component( i can't find the package com.sun.LWUIT)
    i tried to use customItem but i can't add it into the form

  10. #10
    Registered User
    Join Date
    Aug 2013
    Posts
    5

    Re: problem with pie chart in a specefic form

    Quote Originally Posted by hamishwillee View Post
    Please use the platform specific discussion boards - these have more "expert" eyes working on them. I have moved this.
    thanks but where do you post it???

  11. #11
    Registered User
    Join Date
    Aug 2013
    Posts
    5

    Pie Chart using CustomItem?????

    hello,
    i want to insert a pien chart in a specific form, how can i do that using customItem???
    it's very urgent
    thanks for advance

  12. #12
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,535

    Re: problem with pie chart in a specefic form

    Quote Originally Posted by sana92 View Post
    thanks but where do you post it???
    You missed what was written..its already moved to the right place.

    Quote Originally Posted by hamishwillee View Post
    I have moved this.

  13. #13
    Regular Contributor
    Join Date
    Dec 2012
    Location
    India
    Posts
    271

    Re: problem with pie chart in a specefic form

    Your PieChart creating code is done by extending Canvas. You cannot add a canvas to a form.A form or canvas is a displayable object, that can be shown as such and cannot be added as an Item to a Form.

    I would suggest that the best way for you would be to create a LWUIT component like gaba88 suggested.

    The LWUIT JAR is available along with the Asha SDK or can be downloaded individually from here

    https://projects.developer.nokia.com...for_Series_40/

    Add the LWUIT Jar to your project and you will be able to reference com.sun.lwuit.

  14. #14
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: problem with pie chart in a specefic form

    Quote Originally Posted by sana92 View Post
    thanks for your reply, but it's impossible to convert my pie chart into a LWUIT component( i can't find the package com.sun.LWUIT)
    i tried to use customItem but i can't add it into the form
    arunkam has already mentioned either you use the Nokia asha sdk or somehow use the LWUIT library in your application, any one of them will solve your problem !!

  15. #15
    Nokia Developer Champion
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    3,087

    Re: Drawing a pie chart on a Form

    Quote Originally Posted by sana92 View Post
    please Infms, i'm facing the same problem, can you tell me how did you fix it exactly thanks for advance
    Where are you stuck in making the pie-chart or in adding it to the form ?
    thanks,
    ~Amitabh
    (Champion of the Month -Aug'13)
    Follow me on my blog for Innovative Mobile Apps

Similar Threads

  1. Drawing Pie Chart in Symbian
    By sunitha.m13 in forum Symbian User Interface
    Replies: 7
    Last Post: 2010-05-22, 13:57
  2. Bar chart
    By apnasi in forum Mobile Java General
    Replies: 7
    Last Post: 2010-04-01, 10:26
  3. Symbian API chart?
    By Corvus9 in forum Symbian Tools & SDKs
    Replies: 8
    Last Post: 2009-09-16, 07:41
  4. make pie chart
    By sapramit in forum Symbian
    Replies: 1
    Last Post: 2005-05-19, 10:12
  5. Database and chart example?
    By thomasv in forum Symbian
    Replies: 1
    Last Post: 2004-04-02, 15:32

Posting Permissions

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