Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graphs.

 
dhwani mathur
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 48968
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 621
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks larry i found your code to be interesting.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic