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 11 of 11

Thread: Need help with pie charts locations

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

    Default Need help with pie charts locations

    How to make centers for multiple pie charts using for loop?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with pie charts locations

    What code are you having problems with? Please post the code and your questions.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need help with pie charts locations

    Quote Originally Posted by Norm View Post
    What code are you having problems with? Please post the code and your questions.
    public int getCenterPoint(int x1,int y1){

    int xCenter = getWidth()/ 2;
    int yCenter = getHeight()/ 2;
    int radius = (int) (Math.min(getWidth(), getHeight()) * 0.4);
    int diameter = 2 * radius;
    int row = dcRef.columns[0].array.length; // number of rows

    for (int i=0; i<row; i++) { // here is the problem (dead code)

    x1 = xCenter - radius ;
    y1 = yCenter - radius;
    x1 = x1 + diameter + i;
    return x1;
    }


    return y1;
    }

    How to get centers for multiple pie charts?
    Last edited by Wise girl; June 13th, 2012 at 02:44 PM.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with pie charts locations

    The return x1 inside the loop will end the loop immediately.
    The getCenterPoint() method returns an int value. Does a point have two values: x & y How is one int value a point?

    Please describe what that method is supposed to do. It is passed: x & y (a point?) and then does what?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need help with pie charts locations

    Yes, it returns points x & y. I will call this method then in another method that plots the pie charts.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with pie charts locations

    The method only returns one int, not two ints. It either returns x or it returns y, not both.
    Can you describe the steps the method should take to compute values and what value(s) it should return?
    There is a class: Point that can hold an x & y value if you want to return them.

    The x1 and y1 values passed to the method are not used???
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need help with pie charts locations

    I wanna call that method in this method

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


    Color color[] = {Color.pink,
    Color.blue,
    Color.white,
    Color.blue,
    Color.red};


    int row = dcRef.columns[0].array.length;
    int col = dcRef.columns.length;

    double sum = 0.0;
    for (int i = 0; i < row; i++) {
    for (int j = 0; j < col; j++){
    sum += dcRef.columns[j].array[i];

    }
    }


    for (int i=0; i<row; i++) {

    this.getCenterPoint(x1, y1); // call

    for (int j=0; j<col; j++){

    int startAngle = (int)( j* 360 / sum);
    int arcAngle = (int)( i * 360 / sum);

    if (i == row-1) {
    arcAngle = 360 - startAngle;
    }

    Color co = color[j];
    g.setColor(co);


    g.fillArc(x1 , y1, width, height ,startAngle, arcAngle );

    startAngle+=arcAngle;


    }

    }
    }

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with pie charts locations

    Please explain what you want the getCenterPoint method to do. What parameters does it need, what values will it compute and what will it return.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need help with pie charts locations

    I want it to hold the values of x & y

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need help with pie charts locations

    Methods do not HOLD values.
    Use the Point class if you want something to hold the values of x & y
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need help with pie charts locations

    Ok, I will try that.

Similar Threads

  1. stock charts...
    By theChameleon in forum Java Theory & Questions
    Replies: 1
    Last Post: February 24th, 2011, 05:11 AM
  2. Implementation of 3D char and use of Jfreechart
    By tomcat in forum Java Servlet
    Replies: 3
    Last Post: June 8th, 2009, 10:17 AM