Click here to Skip to main content
15,558,870 members
Articles / Desktop Programming / WPF
Posted 15 May 2011


121 bookmarked

WPF Toolkit Charting Controls (Line, Bar, Area, Pie, Column Series) Demo

Rate me:
Please Sign up or sign in to vote.
4.91/5 (38 votes)
15 May 2011CPOL3 min read
This article shows you how you can display information using WPF Toolkit chart controls.


I’m currently working on a few Data Visualization projects and am using WPF most of the time. Charting controls are very useful for the one related to statistics and data handling. WPF toolkit is free and open source, however is used by few because of its limited charting support. In my opinion, it is quite useful and straightforward to use.

Here, I’m just demonstrating the basic charting controls and setting data for display. For articles related to this in future, I shall demonstrate advanced features of WPF Toolkit.


No prior knowledge of WPF is required. You just need to be aware of HTML (which I’m pretty sure everyone is, nowadays). XAML coding is pretty fun.

Firstly, I’ll mention the installation steps and then will dive into coding XAML and related C# files for visualizing static set of data.

First Step – Install WPF Toolkit

Install WPF Toolkit from this site:

(Please check the installation and usage instructions as mentioned here.)

Add new WPF application in Visual Studio.

If you are not able to view chart controls in Toolbox, right click Toolbox and select Choose Items. Then click on WPF components and select chart controls (the ones mentioned in the title). This will add the controls to your toolbox and you should be able to drag and drop them on the XAML form.

Second Step – XAML Coding for Charting Controls

XAML (Extensible Application Markup Language) is a markup language for declarative application programming. If you are interested in knowing more about XAML, please refer to the MSDN documentation at

As you can see in the following MainWindow.xaml code, there are a lot of <chartingToolkit:Chart> tags, each one refers to the 5 different charting controls that we are going to use.

<Window x:Class="WpfToolkitChart.MainWindow"
        Title="MainWindow" Height="1031" Width="855" xmlns:chartingToolkit=
    <ScrollViewer HorizontalScrollBarVisibility="Auto" 
	VerticalScrollBarVisibility="Auto" Margin="0,-28,0,28">
        <Grid Height="921">
            <chartingToolkit:Chart Height="262" HorizontalAlignment="Left" 
		Margin="33,0,0,620" Name="columnChart" Title="Column Series Demo" 
		VerticalAlignment="Bottom" Width="360">
                <chartingToolkit:ColumnSeries DependentValuePath="Value" 
		IndependentValuePath="Key" ItemsSource="{Binding}" />              
            <chartingToolkit:Chart  Name="pieChart" Title="Pie Series Demo" 
		VerticalAlignment="Top" Margin="449,39,43,0" Height="262">
                <chartingToolkit:PieSeries DependentValuePath="Value" 
		IndependentValuePath="Key" ItemsSource="{Binding}" 
		IsSelectionEnabled="True" />
            <chartingToolkit:Chart  Name="areaChart" Title="Area Series Demo" 
		VerticalAlignment="Top" Margin="33,330,440,0" Height="262">
                <chartingToolkit:AreaSeries DependentValuePath="Value" 
		IndependentValuePath="Key" ItemsSource="{Binding}" 
            <chartingToolkit:Chart  Name="barChart" Title="Bar Series Demo" 
		VerticalAlignment="Top" Margin="449,330,43,0" Height="262">
                <chartingToolkit:BarSeries  DependentValuePath="Value" 
		IndependentValuePath="Key" ItemsSource="{Binding}" 
            <chartingToolkit:Chart  Name="lineChart" Title="Line Series Demo" 
		VerticalAlignment="Top" Margin="33,611,440,0" Height="254">
                <chartingToolkit:LineSeries  DependentValuePath="Value" 
		IndependentValuePath="Key" ItemsSource="{Binding}" 

Beginning with the <window> tag, you can see that there is an attribute that says xmlns:chartingToolkit which is basically a namespace referring to the added WPF Toolkit.

I’ve used <ScrollViewer> tag in order to add horizontal and vertical scrollbars to the XAML page.

Now starting with first charting control, columnChart, drag and drop the column series control in toolbox on XAML page and you will see a rectangle with nothing inside. Look in the XAML window (usually below the Designer), and you will see:

<chartingToolkit:ColumnSeries DependentValuePath="Value" 
IndependentValuePath="Key" ItemsSource="{Binding}" />

Now all the charting controls needs to be encapsulated in <chartingToolkit:Chart> (which is a good practice). It has different attributes such as height, horizontal alignment, name, title, width, etc. which are just concerned with the way in which it appears on the page.

Our basic concern is understanding the attributes of <chartingTookit:columnSeries> here and in all other charting controls. I’m using three attributes. DependentValuePath and IndependentValuePath are related to the Axis of the Chart (i.e. X-axis, Y-axis). “Value” and “Key” as assigned to them respectively - this is because I’m using KeyValuePair<> data type in my data model (which has Key and Value). You can also use Dictionary or any other data type by just making sure that you have two parameters that are interdependent for visualization. Itemsource attribute is used for binding our data to the control.

Follow the same as above for all the other controls as mentioned and now we shall assign the data model to the controls.

Third Step – Assigning Data Model to the Controls

As you can see in the MainWindow.xaml.cs file, it is pretty straightforward with the way we are assigning data model.

namespace WpfToolkitChart
  /// <span class="code-SummaryComment"><summary>
</span>  /// Interaction logic for MainWindow.xaml
  /// <span class="code-SummaryComment"></summary>
</span>  public partial class MainWindow : Window
    public MainWindow()

    private void showColumnChart()
      List<KeyValuePair<string, int>> valueList = new List<KeyValuePair<string, int>>();
      valueList.Add(new KeyValuePair<string, int>("Developer",60));
      valueList.Add(new KeyValuePair<string, int>("Misc", 20));
      valueList.Add(new KeyValuePair<string, int>("Tester", 50));
      valueList.Add(new KeyValuePair<string, int>("QA", 30));
      valueList.Add(new KeyValuePair<string, int>("Project Manager", 40));

      //Setting data for column chart
      columnChart.DataContext = valueList;

      // Setting data for pie chart
      pieChart.DataContext = valueList;

      //Setting data for area chart
      areaChart.DataContext = valueList;

      //Setting data for bar chart
      barChart.DataContext = valueList;

      //Setting data for line chart
      lineChart.DataContext = valueList;


I’m using static list with 5 entries. DataContext is the property assigned to charting controls and you can assign the list directly to the controls and you are good to go.

Fourth Step – Compile and Run

Compile and run and you should see the following:



I hope this article provides you with enough assistance to keep the work going on for visualizing information. Information Visualization is changing the way people look at data and in my view, it is going to play a key role in future.

I’ll explain advanced features related to assigning complex data model to controls in the future.


  • 15th May, 2011: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

GeneralRe: WPF Toolkit Charting Controls (Line, Bar, Area, Pie, Column Series) Demo Pin
Priyank Kabaria1-Nov-11 9:42
Priyank Kabaria1-Nov-11 9:42 
Questiongreat sample Pin
Andre Suchitra5-Sep-11 18:06
Andre Suchitra5-Sep-11 18:06 
AnswerRe: great sample Pin
Priyank Kabaria5-Sep-11 18:26
Priyank Kabaria5-Sep-11 18:26 
QuestionGreat demo! Pin
patzerFish28-Jul-11 11:04
patzerFish28-Jul-11 11:04 
AnswerRe: Great demo! Pin
Priyank Kabaria29-Jul-11 9:56
Priyank Kabaria29-Jul-11 9:56 
QuestionGood example Pin
Roger S. Mikalsen24-Jun-11 4:48
Roger S. Mikalsen24-Jun-11 4:48 
AnswerRe: Good example Pin
Priyank Kabaria29-Jul-11 9:55
Priyank Kabaria29-Jul-11 9:55 
GeneralTutorial Pin
Paul Selormey15-May-11 15:37
Paul Selormey15-May-11 15:37 
Please provide a real tutorial instead of just throwing in a sample.
Also, avoid providing a link to a particular release of the chart library.

Best regards,

Jesus Christ is LOVE! Please tell somebody.

GeneralRe: Tutorial [modified] Pin
Priyank Kabaria15-May-11 17:52
Priyank Kabaria15-May-11 17:52 
GeneralRe: Tutorial Pin
Sirstrafe16-May-11 4:19
Sirstrafe16-May-11 4:19 
GeneralRe: Tutorial PinPopular
Priyank Kabaria16-May-11 19:52
Priyank Kabaria16-May-11 19:52 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.