How to use wpf chart

By aj li

Simple step on how to use wpf toolkit chart

This assumes that you have installed latest wpf toolkit from codeplex.

1.  Add this reference in your project = System.Windows.Controls.DataVisualization.Toolkit

2.  In your xaml file, you have the namespace:
xmlns:charting="clr-namespace:System.Windows.Controls.DataVisualization.Charting; assembly=System.Windows.Controls.DataVisualization.Toolkit"

3. Then your chart:

<charting:Chart Margin="8" Height="550" Title="Number of Sales by Region">
<charting:Chart.Series>
<charting:ColumnSeries DependentValueBinding="{Binding Value}" IndependentValueBinding="{Binding Key}" ItemsSource="{Binding RegionalSales}" Title="Number of Sales">
   <charting:ColumnSeries.DependentRangeAxis>
      <charting:LinearAxis Minimum="0" Orientation="Y" Title="Quantity" />
   </charting:ColumnSeries.DependentRangeAxis>
     <charting:ColumnSeries.IndependentAxis>
                      <charting:CategoryAxis Orientation="X"  Title="Region" />
     </charting:ColumnSeries.IndependentAxis>
   </controls:ScrollableColumnSeries>
  </charting:Chart.Series>
</charting:Chart>

4.  Then in your viewmodel or your code behind, the RegionalSales is declared as dictionary and just fill it up with key-value pairs. In the example code above, the key = x axis, value = y axis.

Dictionary<string, int> RegionalSales

How to use wpf chart  (2145 Views)