Data-Binding

This section describes data binding.

The steps required to create data bound charts are identical to the ones we mentioned in the earlier topics

1.   Choose the chart type (ChartType property).

2.   Set up the axes (AxisX and AxisY properties).

3.   Add one or more data series (Children collection).

4.   Adjust the chart's appearance using the Theme and Palette properties.

The only difference is in step 3. When you create data-bound charts, you need to set the ItemsSource property to the collection of items that contain the data you want to chart. Then, use the dataSeries.ValueBinding property to specify which property of the items contains the values to be plotted.

For example, here is the code we used before to generate the Sales Per Region chart (not data-bound):

      C#

Here is the data-bound version of the code (changes are highlighted). The result is identical:

      C#

The data-bound version of the code is even more compact than the original. The three series are created in a loop, taking advantage of the fact that the names of the properties we want to chart are the same as the names we want to use for each data series.

You can assign any object that implements the IEnumerable interface to the ItemsSource property. This includes simple lists as shown above and LINQ queries.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.