Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 13 of 13

Thread: Help with pie chart

  1. #1
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Help with pie chart

    How to draw multiple pie charts according to DArray, and how to compute scale factor for 400*300?
    Last edited by Wise girl; June 1st, 2012 at 03:41 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with pie chart

    What packages and classes are you trying to use for your project? Have you done a Google search for packages that will do pie charts?
    Last edited by Norm; June 1st, 2012 at 09:57 AM. Reason: removed comment about location
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Help with pie chart

    Thead moved to Java Theory & Questions

  4. #4
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with pie chart

    I use Guiapp class and plot button that plot the charts of Drawing Canvas class( which draw the pies)

    Is this code correct:
    String cmd = "arc" x + " " + y + " " + theta + " " + color;

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with pie chart

    Is this code correct:
    Does it compile? Does it create a String?
    What do you want to resultant String to contain?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with pie chart

    I want it to contain the DArray of cols and rows that is in the file text

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with pie chart

    What will the String: cmd be used for?

    What is DArray? Is it a java package you are using? I've never seen any reference to it and can only suggest that you rread the doc that comes with the package.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with pie chart

    That what I have in DrawingCanvas class,but I do not how to do PlotButtonAction class that plots the pie charts.

    public class DrawingCanvas extends JPanel {

    int width;
    int height;
    ActionContainer acRef = null;

    DrawingCanvas(int width, int height, ActionContainer acRef) {
    this.acRef = acRef;
    this.width = width;
    this.height = height;
    }

    public DrawingCanvas(BorderLayout borderLayout) {

    }

    private void execute(String actionLine, Graphics g) {
    System.out.println("action=" + actionLine);

    String array[] = actionLine.split(" ");
    /*Color cArray[] = {
    Color.red,
    Color.white,
    Color.blue,
    Color.green,
    Color.black
    };*/
    int xCenter = getWidth()/ 2;
    int yCenter = getHeight()/ 2;
    int radius = (int) (Math.min(getWidth(), getHeight()) * 0.4);
    int x1 = xCenter - radius;
    int y1 = yCenter - radius;
    int x2 = xCenter - radius;
    int y2 = yCenter - radius;
    int x3 = xCenter - radius;
    int y3 = yCenter - radius;


    DArray[] slices= null;
    double total = 0.0D;
    for (int i=0; i<slices.length; i++) {
    total += slices[i].value;
    }


    double curValue = 0.0D;
    int startAngle = 0;
    for (int i=0; i<slices.length; i++) {

    startAngle = (int)(curValue * 360 / total);
    int arcAngle = (int)(slices[i].value * 360 / total);


    if (i == slices.length-1) {
    arcAngle = 360 - startAngle;
    }


    /*if (array[0].equals("arc")) {
    int x1 = Integer.parseInt(array[1]);
    int y1 = Integer.parseInt(array[2]);
    int x2 = Integer.parseInt(array[3]);
    int y2 = Integer.parseInt(array[4]);
    int colorIndex = Integer.parseInt(array[5]);
    Color c = cArray[colorIndex];
    g.setColor(c);*/
    g.setColor(slices[i].color);
    g.fillArc(x1,y1,width, height, startAngle, arcAngle);
    g.fillArc(x2,y2,width, height, startAngle, arcAngle);
    g.fillArc(x3,y3,width, height, startAngle, arcAngle);
    }

    }

    protected void paintComponent(Graphics g) {
    super.paintComponent(g);

    while( ! acRef.empty() ) {
    String action = acRef.pop();
    execute(action, g);
    }
    }
    }

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with pie chart

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting


    The posted code won't compile because it is missing the import statements.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with pie chart

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Graphics;
    import javax.swing.JPanel;

  11. #11
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with pie chart

    Do you have any idea about how to do PlotButton construction action?

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Help with pie chart

    Please Edit your post and wrap your code with[code=java]<YOUR CODE HERE>[/code] to get highlighting

    I don't know anything about a PlotButton.
    Last edited by Norm; June 2nd, 2012 at 07:36 PM.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Junior Member
    Join Date
    Jun 2012
    Posts
    20
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Help with pie chart

    Thank you a lot.

Similar Threads

  1. Google Chart from database Servlet not working
    By bekimdisha in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 14th, 2012, 07:08 AM
  2. scatterplot chart
    By anikal in forum AWT / Java Swing
    Replies: 2
    Last Post: August 23rd, 2011, 11:47 PM
  3. [SOLVED] JFree chart Exception
    By BerilChandra in forum What's Wrong With My Code?
    Replies: 3
    Last Post: April 10th, 2011, 08:52 PM
  4. gui to make a flow chart.
    By Abhinav in forum AWT / Java Swing
    Replies: 1
    Last Post: January 27th, 2010, 02:04 AM
  5. How to create pie or other diagrams in jsp page?
    By sundarjothi in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: July 8th, 2009, 06:44 AM