Tuesday, June 29, 2010

Using the Charts/Graphs of Silverlight Toolkit

Recently I got a task of developing a Silverlight user control that displays charts for various data sets. This implied that I study and understand the charts provided in the Silverlight toolkit. Therefore, I started learning the How-Tos of it. Although there is a sample application provided with the toolkit but the code is quite lengthy and some people like me prefer a quick start before diving into the details. Therefore I simplified the example and now it is being shared so that others can take advantage of it.
The basic ingredients include instances of

  • Chart

  • DataPointSeries (When it is desired to draw, Pie, Line, Bar, Column, Bubble and Scatter graph)

  • An instance of IEnumerable interface



Following is the code that displays a pie chart. Comments have been included so that the code is better understood.

Don't forget to import the following

using System.Windows.Controls.DataVisualization.Charting;
using System.Windows.Data;