• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

servlet graph

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all,
All of the above should be enough to get me going.
 
Ew. You guys are ugly with a capital UG. Here, maybe this tiny ad can help:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic