Thursday, February 10, 2011

Using the Google Chart API to send images in response to a GET request

While we are finalizing the design for our project, we've each been working on a different small task. The task I've been working on is implementing the ability for the user to make a chart based on the data set they are looking at. They should be able to say "hey, I want to see the number of concerts each year from 1990-2010," and it should work. To do this, I've been using the Google Chart API to generate the chart on the servlet and then send it to the client.
To accomplish this, I've been following this answer to a question on stackoverflow.com The process works like this:
  1. Client sends a POST request to the servlet with parameters specifying the data set and ranges to use
  2. Servlet builds a GraphBean object from the client's request and sends it to a GraphBuilder
  3. GraphBuilder constructs a url and sends a GET request to the Google Chart API url
  4. The image generated is given a unique id and stored in the servlet class
  5. The servlet writes a response that references the unique image id in an image tag
  6. The image tag sends a new request to the servlet with that image id, and the servlet sends the image back
  7. The image is removed from the servlet
Actually, the last 4 steps aren't implemented yet, but I expect to have them done soon. I've been developing the first steps in a regular java application instead of using servlets. However, the integration with the servlet will be (hopefully) painless. Once this is done, we should get some nice pictures out of it when our database is set up.

No comments:

Post a Comment