File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes Graph Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Graph" Watch "Graph" New topic


dorjee gyaltsen

Joined: Dec 29, 2004
Posts: 4
can anyone give me the basic java code to create a simple line graph for my java program output.
thanks a lot in advance.
Shashank Agarwal
Ranch Hand

Joined: May 20, 2004
Posts: 105
Well i cant give you the code but maybe u can use this suggestion.

Java considers the upper left hand corner as 0,0 whereas your graph could have the 0,0 at java's 50,50 or any other such co-ordinate.

What you can do is first of all treat X axis and Y axis individually.
To get a point in java consider this simple example

Suppose you have an applet of size 100 x 100. So arbitarily i decide to take 50,50 as the origin of the graph.

Now, draw a horizontal line from 0,50 to 100,50 (of Java) as X Axis and a vertical line from 50,0 to 50,100 as Y axis.

Now if the first point in XY Co-ordinates is 10,20 Then establish the point as (50+10),(50-20) on the canvas's co-ordinates. Similarly, point 30,0) will be 80,50 on the canvases Coordinates.

I hope that helped.
I agree. Here's the link:
subject: Graph
It's not a secret anymore!