Hello Melvin,
Here is a sample code snippet that demonstrates how to declare the mappings in the viewmodel and bind them to the chart instance in XAML:
XAML
C#
using
System.Collections.Generic;
using
System.Windows.Controls;
using
Telerik.Windows.Controls;
using
Telerik.Windows.Controls.Charting;
namespace
SilverlightApplication1
{
public
partial
class
MainPage : UserControl
{
public
MainPage()
{
InitializeComponent();
}
}
public
class
ViewModel : ViewModelBase
{
private
SeriesMappingCollection mappings;
public
ViewModel()
{
var temp =
new
SeriesMappingCollection();
var sm =
new
SeriesMapping();
sm.SeriesDefinition =
new
StackedBarSeriesDefinition();
sm.ItemMappings.Add(
new
ItemMapping(
"Category"
, DataPointMember.XCategory));
sm.ItemMappings.Add(
new
ItemMapping(
"Data"
, DataPointMember.YValue));
sm.ItemsSource =
new
List<ChartData>()
{
new
ChartData(
"C1"
, 1),
new
ChartData(
"C2"
, 5),
new
ChartData(
"C3"
, 7)
};
temp.Add(sm);
var sm2 =
new
SeriesMapping();
sm2.SeriesDefinition =
new
StackedBarSeriesDefinition();
sm2.ItemMappings.Add(
new
ItemMapping(
"Category"
, DataPointMember.XCategory));
sm2.ItemMappings.Add(
new
ItemMapping(
"Data"
, DataPointMember.YValue));
sm2.ItemsSource =
new
List<ChartData>()
{
new
ChartData(
"C1"
, 10),
new
ChartData(
"C2"
, 7),
new
ChartData(
"C3"
, 18)
};
temp.Add(sm2);
this
.Mappings = temp;
}
public
SeriesMappingCollection Mappings
{
get
{
return
this
.mappings;
}
set
{
if
(
this
.mappings != value)
{
this
.mappings = value;
this
.OnPropertyChanged(
"Mappings"
);
}
}
}
}
public
class
ChartData
{
public
ChartData(
string
c,
double
d)
{
this
.Category = c;
this
.Data = d;
}
public
string
Category {
get
;
set
; }
public
double
Data {
get
;
set
; }
}
}
Greetings,
Bart.