• 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

Graphs.

 
Ranch Hand
Posts: 621
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks larry i found your code to be interesting.
reply
    Bookmark Topic Watch Topic
  • New Topic