I needed a simple chart control. I briefly thought about the new ASP.NET Chart control, but that is .NET 3.5 and my current code base is still .NET 2.0. I probably could migrate the code to 3.5 painlessly enough, but “if it ain’t broke…”. I have some experience with amCharts, and they provide an option to use any of their products for freeda, with the only limitation being a small link to their web site being displayed in the top left corner of every chart.
I had read about the Google Chart API in a couple of places so I decided to give it a spin for my simple needs:
The Google Chart API returns a PNG-format image in response to a URL. Several types of image can be generated, including line, bar, and pie charts. For each image type, you can specify attributes such as size, colors, and labels.
The Google Chart API lets you dynamically generate charts. To see the Chart API in action, open up a browser window and copy the following URL into the address bar:
Press the Enter or Return key and - presto! - you should see the following image:
My first thoughts were:
- "seems simple enough, it’s just an <img> tag with the source set to the Google charts API url with bunch of different querystring params to define the data and formatting"
- followed by "all those querystring params look complicated"
- followed by “okay the pie chart is cool, but I need a line chart”.
The following url emits the below image:
After that I was able to grab the url, place it in my code and use some string formatting to replace the data, titles, etc. with dynamically generated data.
The Google Chart API is probably not a solution for your enterprise charting needs, but it will help you put together some simple charts easily for your run-of-the-mill web application. Two of the best things about it that make it easy to work with:
- The documentation is good enough, making it fairly easy to figure out how to do whatever it is you’re trying to do
- Because it is URL based you can keep experimenting with your charts by simply changing values in the URL – no code , no test harness, just a browser and a little time and patience.
You can check out my use of Google Charts at the following: