How to draw multiple pie charts according to DArray, and how to compute scale factor for 400*300?
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 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.
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.
Thead moved to Java Theory & Questions
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;
Does it compile? Does it create a String?Is this code correct:
What do you want to resultant String to contain?
If you don't understand my answer, don't ignore it, ask a question.
I want it to contain the DArray of cols and rows that is in the file text
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.
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);
}
}
}
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.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import javax.swing.JPanel;
Do you have any idea about how to do PlotButton construction action?
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.
Thank you a lot.