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:
_http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250x100&chl=Hello|World_
Press the Enter or Return key and - presto! - you should see the following image:
My first thoughts were:
I hit up the line charts section of the documentation, created a simple chart, then just kept experimenting with different settings, parameters, and labels until I had something that looked decent.
The following url emits the below image:
http://chart.apis.google.com/chart?
cht=lc
&chd=t:0,1.91,1.91,1.92,1.93,1.94
&chds=0,2
&chs=500x250
&chl=Big+Bang|4/14/2009
&chtt=TFF+Ratio+for+Dave+Donaldson
&chxt=y
&chxr=0,0,2
&chm=N*f2*,000000,0,-1,11
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:
You can check out my use of Google Charts at the following:
http://twitterratio.com/history.aspx/danhounshell
http://twitterratio.com/history.aspx/arcware
http://twitterratio.com/history.aspx/jeffhunsaker
http://twitterratio.com/history.aspx/scottw