This week's book giveaway is in the Design forum.We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!

# servlet graph

Tom Caldwell
Ranch Hand
Posts: 39
Can someone point to a book or some code that does a simple line graph in a servlet? I've done very little with graphs and just looking for a simple place to start.
Thanks

William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
Is it generating the image or the algorithm for graphing that is giving you trouble? Most servlet books (mine included) show how to generate a dynamic image. Generating graphs is mainly a problem of getting the scaling algorithm right and figuring out the transformation from your coordinates to "upper left = 0,0" coordinates.
Bill

Tom Caldwell
Ranch Hand
Posts: 39
The algorithm,
It was mainly your books that got me certified so I ordered the servlet book even before it came out, and I see the Go board on page 89, but I think I'm looking for something simpler. I've got a servlet that reads from DB2 and creates a bar graph(only by stretching a gif)and I'm trying to just make a simple line graph instead.

William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
Well, it has been a long time since I have done this, (and that was in Fortran) but the steps in creating a line graph are something like:
1. Determine the final size of the total image and the size of the active graphing area (smaller because of allowing for axis labeling)
You especially need the number of pixels in the X and Y directions for the active area.
2. Determine the range of data values to be graphed by looking at the entire dataset or from knowing beforehand what the range must be.
You may want to adjust the range to some convenient scale ( 0.0 to 100.0 instead of 0.7 to 83.4)
3. Calculate a conversion factor for X values and one for Y values that you can multiply times the data to get in the int range of pixels.
4. Convert the data to X and Y int arrays
5. Apply offsets to all the points to move the origin of your graph to the active area.
6. Use the Graphics.drawPolyline to draw from the X and Y arrays
.... lots more axis drawing and labeling stuff.
Or you might start with a pre-built blank graph image like I did with the GO board - that way you can get fancy with the axis labeling without having to paint it.
Bill

Axel Janssen
Ranch Hand
Posts: 2166
Tom.
One year ago I used this article as basis for more-or-less quick coding a demo:
http://www.javaworld.com/javaworld/jw-07-1997/jw-07-step.html
Axel

Tom Caldwell
Ranch Hand
Posts: 39
Thanks all,
All of the above should be enough to get me going.