Hi,
I'm working with RadControls for Silverlight Q2 2010 SP2 and I get a null reference exception (line: ds.Definition = seriesDef; see code below) when I try to change chart definition. I think that the code below worked with an older version of RadControls.
XAML:
CS:
I'm working with RadControls for Silverlight Q2 2010 SP2 and I get a null reference exception (line: ds.Definition = seriesDef; see code below) when I try to change chart definition. I think that the code below worked with an older version of RadControls.
XAML:
<
Grid
x:Name
=
"LayoutRoot"
>
<
StackPanel
Orientation
=
"Vertical"
>
<
telerik:RadChart
Height
=
"500"
HorizontalAlignment
=
"Left"
Margin
=
"10,10,0,0"
Name
=
"radChart1"
VerticalAlignment
=
"Top"
Width
=
"500"
/>
<
Button
Content
=
"Bar"
Click
=
"BarChart"
Width
=
"50"
Height
=
"20"
/>
<
Button
Content
=
"Pie"
Click
=
"PieChart"
Width
=
"50"
Height
=
"20"
/>
<
Button
Content
=
"Line"
Click
=
"LineChart"
Width
=
"50"
Height
=
"20"
/>
</
StackPanel
>
</
Grid
>
CS:
public
MainPage()
{
InitializeComponent();
DataSeries ds =
new
DataSeries();
ds.Add(
new
DataPoint { XCategory =
"Item 1"
, YValue = 2 });
ds.Add(
new
DataPoint { XCategory =
"Item 2"
, YValue = 4 });
radChart1.DefaultView.ChartArea.DataSeries.Add(ds);
radChart1.DefaultView.ChartArea.Legend.Visibility = System.Windows.Visibility.Collapsed;
radChart1.DefaultSeriesDefinition =
new
BarSeriesDefinition();
}
private
void
BarChart(
object
sender, System.Windows.RoutedEventArgs e)
{
ChangeDefinition(
new
BarSeriesDefinition());
}
private
void
LineChart(
object
sender, System.Windows.RoutedEventArgs e)
{
ChangeDefinition(
new
LineSeriesDefinition());
}
private
void
PieChart(
object
sender, System.Windows.RoutedEventArgs e)
{
ChangeDefinition(
new
PieSeriesDefinition());
}
private
void
ChangeDefinition(SeriesDefinition seriesDef)
{
DataSeries ds = radChart1.DefaultView.ChartArea.DataSeries[0];
ds.Definition = seriesDef;
radChart1.DefaultView.ChartArea.DataSeries.Clear();
radChart1.DefaultView.ChartArea.DataSeries.Add(ds);
}