File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Need help writing a code involving bar charts! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Need help writing a code involving bar charts!" Watch "Need help writing a code involving bar charts!" New topic

Need help writing a code involving bar charts!

Fahed Ghazali

Joined: May 06, 2001
Posts: 4
hey there..
Im studying Java programing at Uni... n have till now found it to be quite intersting..
I need some help writing code for last weeks lab session.
the details of what the lab involves is here...
I have to create a class that rolls n returns the values thrown by a user specified no. of dice. I have made this class.
also there has to be a method in another class that plots the no.of times a particular number is thrown in form of Bar graphs.
how do I go about doing the bar graphs part?
Ill post you my code tommorrow from Uni.... plz. tell me where I am going wrong.

also I have created a method that draws a rectangle. thing is.... after specifying the x and y axis from where to start.... the rectangle is drawn downwards.
public void drawRectangle(int x, int y, int length, int width){
for (int i=0; i<width; i++){<br /> for (int j=length; j>0; j--){
c.drawLine(x+i, y+j, x+width, y+j);
where "c" is an instance variable pointing to "canvas" class and "drawLine" is a method in "canvas" class that draws a line give x1, y1, x2, y2.
thanx all
hope someone can help me out.
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
i have a bar chart sort of 3d i can share it with you.

Val SCJP <BR>going for SCJD
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Can't you share it with the rest of us .
[This message has been edited by Cindy Glass (edited May 11, 2001).]

"JavaRanch, where the deer and the Certified play" - David O'Meara
Joel Cochran
Ranch Hand

Joined: Mar 23, 2001
Posts: 301
The graphics coordinate system in Java is left to right top to bottom. This explains why your rectangle appears to be drawn upside down...

The first Java program I ever wrote was an Applet to draw diagrams from coordinates stored in a mainframe. I had to go through a lot of gyrations to reverse the polarity of the y coordinates, so believe me I feel your pain!

I'm a soldier in the NetScape Wars...
[This message has been edited by Joel Cochran (edited May 11, 2001).]

Wait a minute, I'm trying to think of something clever to say...<p>Joel
Fahed Ghazali

Joined: May 06, 2001
Posts: 4
thanx mate.....
I would appreciate a copy of the bar chart code...
Ill post my code for the lab soon.. could yall tell me wass wrong with it?
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
The code is not elligant but it draws a simpple bar graph. I am posting it below. Also for some reason getX() and getY on IE does not work and generate Exceptions.
I used fixed data but it could be read from a file and fill an arrays.
<applet code = "Graph.class" codebase = "" width = 400 height = 300></applet>

[This message has been edited by Marilyn deQueiroz (edited May 13, 2001).]
I agree. Here's the link:
subject: Need help writing a code involving bar charts!
Similar Threads
How to shrink/grow lines
illegal start of type!
obtaining drawing coordinants from an array
How does canvas, an exteded JPanel obj have methods getSize(), createImage(size.width, size.height)?
paint() and performance