# Need help with pie charts locations

• June 13th, 2012, 04:27 AM
Wise girl
Need help with pie charts locations
How to make centers for multiple pie charts using for loop?
• June 13th, 2012, 06:44 AM
Norm
Re: Need help with pie charts locations
What code are you having problems with? Please post the code and your questions.
• June 13th, 2012, 02:41 PM
Wise girl
Re: Need help with pie charts locations
Quote:

Originally Posted by Norm
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 ;
x1 = x1 + diameter + i;
return x1;
}

return y1;
}

How to get centers for multiple pie charts?
• June 13th, 2012, 02:48 PM
Norm
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?
• June 13th, 2012, 02:55 PM
Wise girl
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.
• June 13th, 2012, 03:03 PM
Norm
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???
• June 13th, 2012, 03:11 PM
Wise girl
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;

}

}
}
• June 13th, 2012, 03:16 PM
Norm
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.
• June 13th, 2012, 03:20 PM
Wise girl
Re: Need help with pie charts locations
I want it to hold the values of x & y
• June 13th, 2012, 03:22 PM
Norm
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
• June 13th, 2012, 03:28 PM
Wise girl
Re: Need help with pie charts locations
Ok, I will try that.