Geeks With Blogs
AzamSharp Some day I will know everything. I hope that day never comes.

My friend Ben Scheirman blogged about Google Chart API. You can read his post here. The chart API is a URL based API which means you will pass the data in the URL and Google will create a chart for you. This is truly awesome since creating the chart is a pretty hard performance kill operation specially when your chart is very very complex. Delegating this work to Google will save us from the trouble.

Anyway, there are many kinds of graphs that you can plot using the Google Chart API. In the example below I am plotting the vertical bar graph.

Here is the code to create the graph:

 private void CreateChart()

            List<Grade> grades = new List<Grade>();
            grades.Add(new Grade() { Title = "Exam 1", Score = 10 });
            grades.Add(new Grade() { Title = "Exam 2", Score = 30 });
            grades.Add(new Grade() { Title = "Exam 3", Score = 90 });
            grades.Add(new Grade() { Title = "Exam 4", Score = 45 });

            string chartValue = String.Empty;
            string chartScale = String.Empty;

            foreach (Grade grade in grades)
                chartValue += grade.Score + ",";
                chartScale += grade.Title + "|";

            Image img = new Image();
            img.ImageUrl = String.Format(",100&chd=t:{0}&cht=bvg&chxt=x,y&chxl=0:|{1}|9:|0|10|20|30|50",chartValue.TrimEnd(','),chartScale.TrimEnd('|'));


The most important line is the URL that is being populated with the graph scale and values. Check out the graph that is created below:


Pretty awesome right!

Posted on Wednesday, December 12, 2007 8:17 AM | Back to top

Comments on this post: Google Chart API Truly Awesome!!!!!

# re: Google Chart API Truly Awesome!!!!!
Requesting Gravatar...
Yes, their charts are pretty cool, especially the map chart. So easy to configure. I will definitely be using their charts for my web projects.
Left by Jeeremie on Jun 06, 2008 5:59 AM

Your comment:
 (will show your gravatar)

Copyright © Mohammad Azam | Powered by: