How to make centers for multiple pie charts using for loop?
Printable View
How to make centers for multiple pie charts using for loop?
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?
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?
Yes, it returns points x & y. I will call this method then in another method that plots the pie charts.
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???
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;
}
}
}
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.
I want it to hold the values of x & y
Methods do not HOLD values.
Use the Point class if you want something to hold the values of x & y
Ok, I will try that.