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

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

Joined: Oct 09, 2000
Posts: 39

posted

0

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

Joined: Mar 22, 2000
Posts: 12823

5

posted

0

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