aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Graphs. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Graphs." Watch "Graphs." New topic
Author

Graphs.

dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Hi all,
I want to create graphs in java,graphs will be of type profit and loss percentage calculation.As per i have read there are many built in softwares that can be used in my program to draw ,but i am interested in drawing my own graphs by using java API's.can anyone advice me on to which package i must use to draw graph in java.
Thanks in advance...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36563
    
  16
i would use Swing myself. Look at this part of the Java Tutorial. Apart from the fact that all the working is shown inside "main" methods, it is very helpful. Find the bits about JPanels and how to draw lines on them, which I think will be helpful.
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Thanks for your reply,
but one more doubt i have is once the value of X co-ordinat and y co-ordinate gets calculated then which GUI component or method can be used to plot the graph?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36563
    
  16
I would have thought the paintComponent() method of a JPanel is easiest to use.
You find it is passed a Graphics object usually called g; you don't have to find the Graphics object, the JVM or something passes it for you.
Try the g.drawLine() method using the Graphics object.

There isn't a lot I can find on a quick look at the Java Tutorial; look for JPanel here, then sercah for "paintComponent", and Graphics is here. Beware; there is also a paintComponents() method.

Another warning: the y coordinates run from top to bottom.
larry fulkerson
Greenhorn

Joined: Jun 16, 2007
Posts: 3
I have built a moving graph widget using Swing that you might find interesting.



There are three files in this eclipse project and this is the first of the three:


This is the second of three files:


And here is the third of three files:

[ June 17, 2007: Message edited by: larry fulkerson ]
dhwani mathur
Ranch Hand

Joined: May 08, 2007
Posts: 621
Thanks larry i found your code to be interesting.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Graphs.
 
Similar Threads
drawing graph
Graphs support in Java.
Graphs support in Java.
graph drawing
How do I draw bar charts using java api