How to make centers for multiple pie charts using for loop?
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.
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.
If you don't understand my answer, don't ignore it, ask a question.
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.
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.
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???
If you don't understand my answer, don't ignore it, ask a question.
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.
If you don't understand my answer, don't ignore it, ask a question.
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
If you don't understand my answer, don't ignore it, ask a question.
Ok, I will try that.