
GoogleChart Wrapper example
I wrote a simple wrapper class around the GoogleChart API.
What is GoogleChart
GoogleChart is a web service that generate charts images. You call a URL with parameters that describe the values, labels, colors, title, and more. There’s a lot of chart type supported: Line, Pie, Bar, Scatter, …
The following url generate a Hello World Pie chart:
http://chart.apis.google.com/chart?cht=p3&chd=t:60,40&chs=250×100&chl=Hello|World
You can have more details on the GoogleChart API at: http://code.google.com/apis/chart/
WindowsForm integration
The Wrapper that I wrote is simple to use in a Windows Form application. You simply add a PictureBox and assign the Location using the Wrapper GetURL() method. Here is a simple example that demonstrate the use:
private void Form1_Load(object sender, EventArgs e)
{
this.pictureBox1.ImageLocation = SimpleGrid();
}
public static string SimpleGrid()
{
GoogleChartWrapper gc = new GoogleChartWrapper(376, 293, GoogleChartWrapper.ChartType.BarVertical, "Comparaison results\nYet a other line");
gc.TitleColor = Color.Red;
gc.TitleFontSize = 24;
gc.AddDataValues(new double[] { 38, 50, 25, 76, 92, 66, 23 });
gc.ChartColors.Add(Color.Blue);
gc.LegendTitles.Add("Sales");
gc.LegendPlacementPosition = GoogleChartWrapper.LegendPlacement.Right;
gc.AddAxesLabels(new string[] { "0", "55", "100" });
gc.AddAxesLabels(new string[] { "1999", "2000", "2002", "2004", "2005", "2006", "2007" });
return gc.GetURL();
}
Complete Form code example:
Source code