Showing posts with label Google Chart. Show all posts
Showing posts with label Google Chart. Show all posts

Friday, February 11, 2011

Using the Google Chart API (cont'd) and caching images for retrieval

Yesterday I talked about using the Google Chart API on the server to send chart images to a client in response to a query. Today after meeting with my colleague, he revealed a more straightforward approach than trying to cache the generated images and retrieve them from the image tag.

Well, we're still doing that, but instead of generating the image data and sending that, we generate just the url string to send to the google chart site. Then we send that to the client, where it is embedded into an image tag. Now we don't have to cache any image data. However, we still might end up caching it for a simple reason. It would be nice for users to get a quasi-permanent link to a generated graph, so that they could type "address/graph?id=..." instead of having to put up with a Google Chart url string (which might be long depending on the dataset).

There are still some more things to add to the code before it is ready to integrate with the main project, but overall it will make a pretty nice addition.

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.