Creating And Plotting Graphs

M

morc

Hey,
Does anybody know of a tutrial or soemthing i can read that would teach
me how to make a graph and to plot it as well? Simple charts will do
for know but eventualy I need to make stock market related charts.

And please don't refer me to JFreeChart i know its good but it doesn't
help me. I would like to be able to make one on my own. So if anyone
would like to teach me or point me to a tutorial it would be greatly
appreciated.

thanks
-morc
 
R

Rhino

morc said:
Hey,
Does anybody know of a tutrial or soemthing i can read that would teach
me how to make a graph and to plot it as well? Simple charts will do
for know but eventualy I need to make stock market related charts.

And please don't refer me to JFreeChart i know its good but it doesn't
help me. I would like to be able to make one on my own. So if anyone
would like to teach me or point me to a tutorial it would be greatly
appreciated.
I think you'll find drawing graphs is pretty simple. A very basic example of
a graph can be seen at
http://java.sun.com/applets/jdk/1.4/demo/applets/SimpleGraph/example1.html.
If you look at the source code (linked below the applet), you'll see that it
is only a very small number of lines of code to draw this sine wave. If you
want to add axes to the graph, that is basically a matter of drawing two
more straight lines via the g.drawLine() method.

If you want to put tick marks on the axes and label the marks, that's a bit
more work but still no big deal: you simply compute the length of the axis
and the range of values you want to show on the axis, then determine where
the tick marks need to be to represent the desired values. For instance, if
the X axis represents 100 units and is 8 cm long and you want tick marks for
the values 25, 50, 75 and 100, you simply put them at 2 cm, 4 cm, 6 cm, and
8 cm from the origin and label appropriately via drawString().

Naturally, you can add as many bells and whistles as you like, such as the
ability to zoom in or out on the graph, show multiple curves, etc. etc.

I think you'll find everything you need in the Graphics and/or Graphics2D
classes in the Java API. Assuming you are using Swing, simply paint the
various lines, curves, and Strings on a JPanel and you should be off to the
races.
 
I

IchBin

morc said:
Hey,
Does anybody know of a tutrial or soemthing i can read that would teach
me how to make a graph and to plot it as well? Simple charts will do
for know but eventualy I need to make stock market related charts.

And please don't refer me to JFreeChart i know its good but it doesn't
help me. I would like to be able to make one on my own. So if anyone
would like to teach me or point me to a tutorial it would be greatly
appreciated.

thanks
-morc
There is a demo under your JDK install at
...\Java\jdk1.5.0_06\demo\applets\SimpleGraph

So
http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Graphics.html

Examples can be found here in the "The Java Developers Almanac 1.4"

http://www.google.com/custom?num=10...aphics&btnG=Search&sitesearch=javaalmanac.com

Some more info:
http://java.ittoolbox.com/topics/t.asp?t=440&p=440&h1=440

Google is an amazing tool when used..

--

Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
__________________________________________________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top