Hi,
I am following some examples to bind a CartesianChart to a Datatable but I haven't been able to do it, this is my code:
And the code behind:
And when I run the application, the series do not appear.
I am missing something?
Thanks,
Alberto
I am following some examples to bind a CartesianChart to a Datatable but I haven't been able to do it, this is my code:
<
telerik:RadCartesianChart
Name
=
"chartTest"
Margin
=
"10"
Palette
=
"Grayscale"
>
<
telerik:RadCartesianChart.Behaviors
>
<
telerik:ChartPanAndZoomBehavior
PanMode
=
"Both"
ZoomMode
=
"Both"
/>
</
telerik:RadCartesianChart.Behaviors
>
</
telerik:RadCartesianChart
>
And the code behind:
public
class
Chemistry
{
public
string
DESCRIPTION {
get
;
set
; }
public
double
HEATS_IN_PCT {
get
;
set
; }
public
double
HEATS_IN_PCT_LINE {
get
;
set
; }
}
public
class
MainViewModel
{
public
ObservableCollection<Chemistry> Data {
get
;
private
set
; }
public
MainViewModel()
{
this
.Data = GetTestData();
}
private
static
ObservableCollection<Chemistry> GetTestData()
{
var result =
new
ObservableCollection<Chemistry>();
//Custom function to load a stored procedure data
DataTable dtChemistry = DataRetriever.ExecuteRetrieveProcedure(
"SB_QUALITY_CHEMISTRY"
);
foreach
(DataRow dr
in
dtChemistry.Rows)
{
result.Add(
new
Chemistry
{
DESCRIPTION = dr[
"DESCRIPTION"
].ToString(),
HEATS_IN_PCT = (
double
)dr[
"HEATS_IN_PCT"
],
HEATS_IN_PCT_LINE = (
double
)dr[
"HEATS_IN_PCT_LINE"
]
});
}
return
result;
}
}
void
Configure_Chart()
{
BarSeries barSer =
new
BarSeries() { Name =
"barCrew"
};
barSer.ShowLabels =
true
;
barSer.CombineMode = ChartSeriesCombineMode.Cluster;
barSer.LabelDefinitions.Clear();
barSer.LabelDefinitions.Add(
new
ChartSeriesLabelDefinition() { HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center });
Telerik.Windows.Controls.ChartView.LineSeries lineSer =
new
Telerik.Windows.Controls.ChartView.LineSeries() { Name =
"lineCrew"
};
barSer.CategoryBinding =
new
PropertyNameDataPointBinding() { PropertyName =
"DESCRIPTION"
};
barSer.ValueBinding =
new
GenericDataPointBinding<Chemistry,
double
>() { ValueSelector = Chemistry => Chemistry.HEATS_IN_PCT};
//Also used PropertyNameDataPointBinding("HEATS_IN_PCT");
lineSer.CategoryBinding =
new
PropertyNameDataPointBinding() { PropertyName =
"DESCRIPTION"
};
lineSer.ValueBinding =
new
GenericDataPointBinding<Chemistry,
double
>() { ValueSelector = Chemistry => Chemistry.HEATS_IN_PCT_LINE };
//Also used PropertyNameDataPointBinding("HEATS_IN_PCT_LINE");
MainViewModel vm =
new
MainViewModel();
barSer.ItemsSource = vm.Data;
lineSer.ItemsSource = vm.Data;
chartTest.Series.Add(barSer);
chartTest.Series.Add(lineSer);
}
And when I run the application, the series do not appear.
I am missing something?
Thanks,
Alberto