Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graph

 
dorjee gyaltsen
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi!
can anyone give me the basic java code to create a simple line graph for my java program output.
thanks a lot in advance.
cheers!
 
Shashank Agarwal
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic