Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / February 2006

Tip: Looking for answers? Try searching our database.

Creating And Plotting Graphs

Thread view: 
morc - 23 Feb 2006 17:31 GMT
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
Rhino - 23 Feb 2006 19:21 GMT
> Hey,
> Does anybody know of a tutrial or soemthing i can read that would teach
[quoted text clipped - 5 lines]
> 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.

--
Rhino
IchBin - 23 Feb 2006 20:22 GMT
> Hey,
> Does anybody know of a tutrial or soemthing i can read that would teach
[quoted text clipped - 8 lines]
> 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=100&hl=en&lr=&ie=ISO-8859-1&oe=ISO-8859-1&c2cof
f=1&client=pub-6001183370374757&cof=FORID%3A1%3BGL%3A1%3BBGC%3AFFFFFF%3BT%3A%230
00000%3BLC%3A%230000ff%3BVLC%3A%23663399%3BALC%3A%230000ff%3BGALT%3A%23008000%3B
GFNT%3A%230000ff%3BGIMP%3A%230000ff%3BDIV%3A%23336699%3BLBGC%3A336699%3BAH%3Acen
ter%3B&domains=javaalmanac.com&q=Graphics&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..

Signature

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-)



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.