Link to home
Start Free TrialLog in
Avatar of Dawkins
Dawkins

asked on

Easy way to draw a simple graph

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You'd be better off using proper graphing components:

www.jfreechart.org
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Giant2
Giant2

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.
Avatar of Dawkins

ASKER

ok thanks I'll take a look at free chart and get back to you
If you only need a basic graph then drawing it yourself is no big task.
how would you like to graph the data?
Avatar of Dawkins

ASKER

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?
See what I posted before.
> 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);
}
>for (int i=1; i<points.length; i++)
...
>}

in a paint method.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
all is explained into the tutorial I posted before.
Avatar of Dawkins

ASKER

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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
:-)
Thanks for the points, let us know if you have further questions.
Happy to help you.
:)