• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

plotting pie and bar charts

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try thru JFreeChart for chart creation. I guess iReport designer tool supports somw of the chart creation.
 
kanaka tam
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
reply
    Bookmark Topic Watch Topic
  • New Topic