I have a rad cartesian chart i need it to update each time the user choose an item in a datagrid.
This is the code behind:
This is the xaml:
Using this code the chart display the first item, when i choose another one the chart doesn't update with the new datas.
Many thanks :)
This is the code behind:
private
void
dataGrid_SelectionChanged(
object
sender, SelectionChangedEventArgs e)
{
chartdatas.Clear();
chartdatas2.Clear();
VariablesDescription temp = ((DataGrid)sender).SelectedItem
as
VariablesDescription;
if
(temp !=
null
)
{
UpdateVariablesLabels(temp.Name);
if
(temp !=
null
)
{
string
name = temp.Name;
foreach
(ModelVariable model
in
this
.data.ModelVariables)
{
string
comp = model.variableName;
string
[] word = comp.Split(
'.'
);
string
ToCompar = word[word.Length - 1];
if
(ToCompar == name)
{
for
(
int
i = 0; i < model.modalities.Count; ++i)
{
Modality modality =
this
.data.ModelVariables[2].modalities[i];
CharDataclass cd =
new
CharDataclass();
CharDataclass cd2 =
new
CharDataclass();
cd.XValue = modality.Percent_target;
cd.YValue = i;
cd2.YValue = i;
chartdatas.Add(cd);
cd2.XValue = modality.Percent_in_universe;
chartdatas2.Add(cd2);
}
graph1.Series[0].ItemsSource = chartdatas;
graph2.DataContext = chartdatas2;
}
}
}
}
}
This is the xaml:
<
telerik:RadCartesianChart
Height
=
"240"
HorizontalAlignment
=
"Left"
Margin
=
"448,408,0,0"
Name
=
"graph1"
VerticalAlignment
=
"Top"
Width
=
"486"
Zoom
=
"10,1"
>
<
telerik:RadCartesianChart.Behaviors
>
<
telerik:ChartPanAndZoomBehavior
PanMode
=
"Horizontal"
ZoomMode
=
"Horizontal"
/>
</
telerik:RadCartesianChart.Behaviors
>
<
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:CategoricalAxis
/>
</
telerik:RadCartesianChart.HorizontalAxis
>
<
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:LinearAxis
HorizontalLocation
=
"Left"
Name
=
"Axis1"
/>
</
telerik:RadCartesianChart.VerticalAxis
>
<
telerik:BarSeries
CategoryBinding
=
"YValue"
ItemsSource
=
"{Binding}"
ValueBinding
=
"XValue"
>
<
telerik:BarSeries.PointTemplate
>
<
DataTemplate
>
<
Rectangle
Fill
=
"Black"
/>
</
DataTemplate
>
</
telerik:BarSeries.PointTemplate
>
</
telerik:BarSeries
>
<
telerik:LineSeries
CategoryBinding
=
"YValue"
ItemsSource
=
"{Binding}"
Name
=
"graph2"
ValueBinding
=
"XValue"
>
<
telerik:LineSeries.PointTemplate
>
<
DataTemplate
>
<
Ellipse
Fill
=
"Red"
Height
=
"7"
Width
=
"7"
/>
</
DataTemplate
>
</
telerik:LineSeries.PointTemplate
>
<
telerik:LineSeries.VerticalAxis
>
<
telerik:LinearAxis
HorizontalLocation
=
"Right"
Name
=
"Axis2"
/>
</
telerik:LineSeries.VerticalAxis
>
</
telerik:LineSeries
>
</
telerik:RadCartesianChart
>
Using this code the chart display the first item, when i choose another one the chart doesn't update with the new datas.
Many thanks :)