Data Binding to ADO.NET Data Service
The purpose of this tutorial is to show you how to populate a RadChart with data from an ADO.NET Data Service in two ways:
A straight-forward way - plain method calls.
This tutorial will use the Northwind database, which can be downloaded from here.
Before proceeding further with this tutorial you need to create a new application and add a RadChart declaration in your XAML:
The chart control will be populated with the top 10 products from the Northwind database. On the Y axis the UnitPrice property will be displayed.
Add a new SeriesMapping to your chart declaration and set the LegendLabel property to "Products UnitPrice".
Add a new ItemMapping and set the following properties:
FieldName to UnitPrice
DataPointMember to YValue
- Create new Business Object and name it ProductDetail:
Plain Method Calls
Add a reference to your ADO.NET Data Service.
- Switch to the code-behind and add a reference to the NorthWindEntities object__DataServiceContext__.
For more information about how to add a reference to an ADO.NET Data Service and how to create a new instance of the exposed entity, take a look at the Consuming ADO.NET Data Service topic.
Add the following code which will make the initial load of the objects.
Run your demo, the result can be seen on the next image:
Using MVVM Approach
This section will show you how to populate your RadChart control in a MVVM manner.
- Create a new class named NorthwindDataSource.
Add a reference to your ADO.NET Data Service.
In the NorthwindDataSource class add a reference to an ObservableCollection of Categories.
In the NorthwindDataSource class add a reference to the NorthwindEntities object.
- Add the following code in the constructor of the NorthwindDataSource. It will make the initial load of all Categories from the database:
- Declare the NorthwindDataSource object as a resource in your application.
- Update your chart declaration - set the ItemsSource property.
Here it is shown how the final result should look like: