dorjee gyaltsen

Greenhorn

Posts: 4

posted 12 years ago

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!

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

posted 12 years ago

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.

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.

Don't get me started about those stupid light bulbs. |