Saturday, June 27, 2009

Chart Controls for WPF

I few days ago Microsoft released a new version of WPF Toolkit.

http://wpf.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=29117

The good news is that the Chart Components are already officially part from WPF Toolkit.

Until now only Silverlight Toolkit had charts and you had to use a lot of so called “hacks” in order to us them in WPF. For example:
http://yordanpavlov.blogspot.com/2009/03/using-silverlight-charting-control-with.html

Now you can make bar, pie, bubble, scatter, line graphs.....
So review in details the new “cool” charts.

1.Add a reference to the System.Windows.Controls.DataVisualization.Toolki.dll assembly in your project:


2. Add the namespace for the Charting controls

3. Add a chart in XAML :


4. Add
some data in code behind:
public Window1()
{
InitializeComponent();
chart.DataContext = new KeyValuePair[] {

new KeyValuePair("Dog", 30),

new KeyValuePair("Cat", 25),

new KeyValuePair("Rat", 5),

new KeyValuePair("Hampster", 8),

new KeyValuePair("Rabbit", 12) };
}
Here is how charts looks like:


As you can see WPF charts are absolutely the same like Silverlight charts:

http://silverlight.codeplex.com/Wiki/View.aspx?title=Silverlight%20Toolkit%20Overview%20Part%202


So enjoy charting!

1 comments:

Anonymous said...

cool!