Solved

Easy way to draw a simple graph

Posted on 2004-07-30
17
261 Views
Last Modified: 2010-03-31
I have written a program which calculates population sizes over a number of generations.

I would now like to display them in a graph - either in "real time", updating each generation as it is calculated, or if that is too tricky just a single graph once the program finishes is fine.  

I have a basic idea of how to get swing components working, but can't find any information about graphs.  Could anyone help me get this up and running?
0
Comment
Question by:Dawkins
  • 7
  • 4
  • 3
  • +1
17 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 11677050
You'd be better off using proper graphing components:

www.jfreechart.org
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 50 total points
ID: 11677057
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11677069
There are several automatic system to generate graph (withou using even Java), but if you want to create a graph in java you must use the Swing API.
See
http://java.sun.com/docs/books/tutorial/uiswing/
and
http://java.sun.com/products/jfc/

Bye, Giant.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Dawkins
ID: 11678043
ok thanks I'll take a look at free chart and get back to you
0
 
LVL 92

Expert Comment

by:objects
ID: 11681754
If you only need a basic graph then drawing it yourself is no big task.
how would you like to graph the data?
0
 

Author Comment

by:Dawkins
ID: 11704337
ok I've downloaded freechart and it looks good but seems like it will take quite a bit of time getting it to work.

All I need is to display a simple 2D line graph with up to 10 different coloured lines.  Would it be simpler to use swing?
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11705928
See what I posted before.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11705941
0
 
LVL 92

Expert Comment

by:objects
ID: 11710646
> Would it be simpler to use swing?

most probably.

It probably wouldn't involve a lot more than just:

for (int i=1; i<points.length; i++)
{
   g.drawLine(points[i-1].x, points[i-1].y, points[i].x, points[i].y);
}
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11712586
>for (int i=1; i<points.length; i++)
...
>}

in a paint method.
0
 
LVL 92

Assisted Solution

by:objects
objects earned 100 total points
ID: 11712596
yes that would be in say your paintComponent() method in a panel subclass

public class PlotPanel extends JPanel
{
   public void paintComponent(Graphics g)
   {
       // paint your graph in here
   }
}
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11712614
all is explained into the tutorial I posted before.
0
 

Author Comment

by:Dawkins
ID: 11728299
I've actually found a very simple set of classes for drawing graphs, which I'm going to use as an example:   http://www.jscieng.co.uk/downloads.html
0
 
LVL 12

Accepted Solution

by:
Giant2 earned 100 total points
ID: 11733125
Java for Scientists and Engineers.
I believe it's based on swing, awt...
I suggest you to learn now how to use swing (even for the future).
But, it's your choice. So, good luck!

Bye, Giant.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11896941
:-)
0
 
LVL 92

Expert Comment

by:objects
ID: 11898150
Thanks for the points, let us know if you have further questions.
0
 
LVL 12

Expert Comment

by:Giant2
ID: 11899876
Happy to help you.
:)
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Weekend adv creator 3 54
jdbc error in jsp application 20 64
restrict decimal places for double datatype 10 22
What browser will run Java? 7 72
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question