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
Joined: Oct 09, 2000
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.
Author and all-around good cowpoke
Joined: Mar 22, 2000
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