File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes plotting pie and bar charts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "plotting pie and bar charts" Watch "plotting pie and bar charts" New topic
Author

plotting pie and bar charts

kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Hello folks,
I am trying to write a program that plots a pie chart for five input numbers. Below is my code. I have no compilation errors but i don't see any picture in the screen after excetion. Any help greatly appreciated. I am a beginner trying to learn Java and i tend to make silly mistakes, didn't know what i did this time cause i am not getting any compilation errors.
thank you,
kt


[ July 09, 2005: Message edited by: kanaka tam ]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Because of the integer division, your degreeIncrement variable will always be equal to zero. Subsequently, the arcs you are trying to draw all have angle 0 and that's why you don't see them. The fix is to divide by a float and cast the result to an integer.

Additionally, the line startAngle += degreeIncrement; should be inside the for loop.
kri shan
Ranch Hand

Joined: Apr 08, 2004
Posts: 1373
Try thru JFreeChart for chart creation. I guess iReport designer tool supports somw of the chart creation.
kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Originally posted by John Smith:
Because of the integer division, your degreeIncrement variable will always be equal to zero. Subsequently, the arcs you are trying to draw all have angle 0 and that's why you don't see them. The fix is to divide by a float and cast the result to an integer.

Additionally, the line startAngle += degreeIncrement; should be inside the for loop.


Thanks John. I appreciate you taking time to answer my question. As always, I am very greatful to this forum and great folks like you and others for helping me out.
kt
kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Originally posted by John Smith:
Because of the integer division, your degreeIncrement variable will always be equal to zero. Subsequently, the arcs you are trying to draw all have angle 0 and that's why you don't see them. The fix is to divide by a float and cast the result to an integer.

Additionally, the line startAngle += degreeIncrement; should be inside the for loop.


John,
I had to draw an equivalent bar chart with the same numbers which i did and got the output as well. One little problem is that i need to display the bar vertically. Right now i have got it to display horizontally. I did play with the x and y coordinates but not able to make it display vertically.
Help appreciated,
Thanks,
kt. Here is my complete code
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

One little problem is that i need to display the bar vertically. Right now i have got it to display horizontally. I did play with the x and y coordinates but not able to make it display vertically.


I ran your code, and it displays the bars vertically, as you want. Are you sure that's the code that you are actually running?

kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Originally posted by John Smith:


I ran your code, and it displays the bars vertically, as you want. Are you sure that's the code that you are actually running?



I am extremely sorry. I wanted it to display horizontally instead of it being displayed vertically. Sorry!! you are so kind to run the code. Yeah i wanted it to be displayed horizontally.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
The third and fourth arguments in Rectangle2D.Double() are width and height, respectively. With that in mind, to show the bars horizontally, your code would look something like this:

kanaka tam
Ranch Hand

Joined: Jan 19, 2004
Posts: 42
Originally posted by John Smith:
The third and fourth arguments in Rectangle2D.Double() are width and height, respectively. With that in mind, to show the bars horizontally, your code would look something like this:



Thanks, John. I appreciate your help. I got the bar chart the way I wanted. I couldn't have come this far without the help of this forum and help from folks like you and others.
kt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: plotting pie and bar charts