it seems that replacing the itemssource of a chart which is in a unselected tab does not clear its selected datapoints.
This becomes evident if you call clearselections on the chartarea.
It causes an exception
i have prepared a little demo code to illustrate.
steps
- click "new source" button
- click "select items"
- click "second tab"
- click "new source" button
- click "select items"
- an exception occurs
System.ArgumentNullException was unhandled by user code
Message=Value cannot be null.
Parameter name: You are trying to select a DataPoint that does not belong to the DataSeries associated with the respective ChartArea.
StackTrace:
at Telerik.Windows.Controls.Charting.ChartArea.VerifyDataPointIsValid(DataPoint dataPoint)
at Telerik.Windows.Controls.Charting.ChartArea.RaiseItemSelectionChangeNotification(DataPoint dataPoint, String selectionState)
at Telerik.Windows.Controls.Charting.ChartArea.UnselectItem(DataPoint dataPoint)
at Telerik.Windows.Controls.Charting.ChartArea.ClearSelection()
at agTestBed3.MainPage.selectitems(ChartArea Chartarea, String Xcategory)
at agTestBed3.MainPage.Button2_Click(Object sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, Int32 actualArgsTypeIndex, String eventName)
InnerException:
<
UserControl
x:Class
=
"agTestBed3.MainPage"
mc:Ignorable
=
"d"
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
>
<
Grid
x:Name
=
"LayoutRoot"
>
<
StackPanel
Orientation
=
"Vertical"
>
<
telerik:RadTabControl
>
<
telerik:RadTabItem
Header
=
"first tab"
>
<
telerik:RadChart
x:Name
=
"chartYears"
UseDefaultLayout
=
"False"
Margin
=
"10"
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"35"
/>
<
RowDefinition
/>
</
Grid.RowDefinitions
>
<
telerik:ChartTitle
Grid.Row
=
"0"
x:Name
=
"charttitle1"
Content
=
"Yearly Breakdown"
/>
<
telerik:ChartArea
Grid.Row
=
"1"
x:Name
=
"chartarea1"
Margin
=
"10"
EnableAnimations
=
"False"
Grid.Column
=
"0"
/>
</
Grid
>
<
telerik:RadChart.SeriesMappings
>
<
telerik:SeriesMapping
LegendLabel
=
"Shipped Revenue"
ChartAreaName
=
"chartarea1"
>
<
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:StackedBarSeriesDefinition
StackGroupName
=
"Revenue"
ShowItemLabels
=
"True"
ShowItemToolTips
=
"True"
LegendDisplayMode
=
"None"
x:Name
=
"barYear"
>
<
telerik:StackedBarSeriesDefinition.Appearance
>
<
telerik:SeriesAppearanceSettings
/>
</
telerik:StackedBarSeriesDefinition.Appearance
>
<
telerik:StackedBarSeriesDefinition.InteractivitySettings
>
<
telerik:InteractivitySettings
SelectionScope
=
"Item"
SelectionMode
=
"Multiple"
/>
</
telerik:StackedBarSeriesDefinition.InteractivitySettings
>
<
telerik:StackedBarSeriesDefinition.LabelSettings
>
<
telerik:BarLabelSettings
LabelDisplayMode
=
"Auto"
ShowZeroValueLabels
=
"False"
/>
</
telerik:StackedBarSeriesDefinition.LabelSettings
>
</
telerik:StackedBarSeriesDefinition
>
</
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:SeriesMapping.ItemMappings
>
<
telerik:ItemMapping
DataPointMember
=
"XCategory"
FieldName
=
"PeriodName"
/>
<
telerik:ItemMapping
DataPointMember
=
"YValue"
FieldName
=
"ShippedRevenue"
/>
</
telerik:SeriesMapping.ItemMappings
>
</
telerik:SeriesMapping
>
<
telerik:SeriesMapping
LegendLabel
=
"Open Revenue"
ChartAreaName
=
"chartarea1"
>
<
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:StackedBarSeriesDefinition
StackGroupName
=
"Revenue"
ShowItemLabels
=
"True"
ShowItemToolTips
=
"True"
LegendDisplayMode
=
"None"
>
<
telerik:StackedBarSeriesDefinition.Appearance
>
<
telerik:SeriesAppearanceSettings
/>
</
telerik:StackedBarSeriesDefinition.Appearance
>
<
telerik:StackedBarSeriesDefinition.InteractivitySettings
>
<
telerik:InteractivitySettings
SelectionScope
=
"Item"
SelectionMode
=
"Multiple"
/>
</
telerik:StackedBarSeriesDefinition.InteractivitySettings
>
<
telerik:StackedBarSeriesDefinition.LabelSettings
>
<
telerik:BarLabelSettings
LabelDisplayMode
=
"Auto"
ShowZeroValueLabels
=
"False"
/>
</
telerik:StackedBarSeriesDefinition.LabelSettings
>
</
telerik:StackedBarSeriesDefinition
>
</
telerik:SeriesMapping.SeriesDefinition
>
<
telerik:SeriesMapping.ItemMappings
>
<
telerik:ItemMapping
DataPointMember
=
"XCategory"
FieldName
=
"PeriodName"
/>
<
telerik:ItemMapping
DataPointMember
=
"YValue"
FieldName
=
"OpenRevenue"
/>
</
telerik:SeriesMapping.ItemMappings
>
</
telerik:SeriesMapping
>
</
telerik:RadChart.SeriesMappings
>
</
telerik:RadChart
>
</
telerik:RadTabItem
>
<
telerik:RadTabItem
Header
=
"Second tab"
>
</
telerik:RadTabItem
>
</
telerik:RadTabControl
>
<
StackPanel
Orientation
=
"Horizontal"
Margin
=
"20"
>
<
Button
Content
=
"New source"
Height
=
"23"
Name
=
"Button1"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Center"
Width
=
"75"
/>
<
Button
Content
=
"Select Items"
Height
=
"23"
Name
=
"Button2"
VerticalAlignment
=
"Center"
HorizontalAlignment
=
"Center"
Width
=
"75"
/>
</
StackPanel
>
</
StackPanel
>
</
Grid
>
</
UserControl
>
Imports
System.Windows.Data
Imports
Telerik.Windows.Controls
Imports
Telerik.Windows.Data
Imports
System.ComponentModel
Imports
System.Collections.ObjectModel
Imports
System.Runtime.CompilerServices
Imports
Telerik.Windows.Controls.Charting
Partial
Public
Class
MainPage
Inherits
UserControl
Public
Sub
New
()
InitializeComponent()
chartYears.ItemsSource =
New
colCustomerOnTimeDelivery
End
Sub
Private
Sub
Button1_Click(sender
As
Object
, e
As
System.Windows.RoutedEventArgs)
Handles
Button1.Click
' add a new itemsource
chartYears.ItemsSource =
New
colCustomerOnTimeDelivery
End
Sub
Private
Sub
Button2_Click(sender
As
Object
, e
As
System.Windows.RoutedEventArgs)
Handles
Button2.Click
' select 2011
selectitems(chartarea1,
"2011"
)
End
Sub
Private
Sub
chartarea1_ItemClick(sender
As
Object
, e
As
Telerik.Windows.Controls.Charting.ChartItemClickEventArgs)
Handles
chartarea1.ItemClick
' select a stack
selectitems(chartarea1, e.DataPoint.XCategory)
End
Sub
Protected
Sub
selectitems(Chartarea
As
ChartArea, Xcategory
As
String
)
If
Chartarea.SelectedItems.Count > 1
Then
Chartarea.ClearSelection()
End
If
Dim
barsInStack
As
New
List(Of DataPoint)
For
Each
item
As
StackedBar
In
Chartarea.ChildrenOfType(Of StackedBar)()
If
item.DataPoint.XCategory = Xcategory
Then
barsInStack.Add(item.DataPoint)
End
If
Next
Chartarea.SelectItems(barsInStack)
End
Sub
End
Class
Public
Class
colCustomerOnTimeDelivery
Inherits
ObservableCollection(Of CustomerOnTimeDeliveryPeriod)
Sub
New
()
MyBase
.
New
()
Dim
zz
As
ObservableCollection(Of CustomerOnTimeDeliveryPeriod) = addYears()
For
Each
CustomerOnTimeDeliveryPeriod
As
CustomerOnTimeDeliveryPeriod
In
zz
Add(CustomerOnTimeDeliveryPeriod)
Next
End
Sub
Public
Function
addYears()
As
ObservableCollection(Of CustomerOnTimeDeliveryPeriod)
Dim
CurrentYear
As
Integer
= Year(Now.
Date
)
Dim
lstYears
As
New
ObservableCollection(Of CustomerOnTimeDeliveryPeriod)
' shipped years
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear - 4, .Children = addMonths(), .ShippedRevenue = 100000})
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear - 3, .Children = addMonths(), .ShippedRevenue = 200000})
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear - 2, .Children = addMonths(), .ShippedRevenue = 300000})
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear - 1, .Children = addMonths(), .ShippedRevenue = 400000})
' current year
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear, .Children = addMonths(), .ShippedRevenue = 500000})
' open years
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear + 1, .Children = addMonths(), .ShippedRevenue = 400000})
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear + 2, .Children = addMonths(), .ShippedRevenue = 300000})
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear + 3, .Children = addMonths(), .ShippedRevenue = 200000})
lstYears.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = CurrentYear + 4, .Children = addMonths(), .ShippedRevenue = 100000})
Return
lstYears
End
Function
Public
Function
addMonths()
As
ObservableCollection(Of CustomerOnTimeDeliveryPeriod)
Dim
lstMonths
As
New
ObservableCollection(Of CustomerOnTimeDeliveryPeriod)
For
x = 1
To
12
lstMonths.Add(
New
CustomerOnTimeDeliveryPeriod
With
{.PeriodName = MonthName(x,
True
), .ShippedRevenue = x * 1000})
Next
Return
lstMonths
End
Function
End
Class
Public
Class
CustomerOnTimeDeliveryPeriod
Public
Property
PeriodName()
As
String
Get
Return
_PeriodName
End
Get
Set
(
ByVal
value
As
String
)
_PeriodName = value
End
Set
End
Property
Protected
_PeriodName
As
String
Public
Property
ShippedRevenue()
As
Decimal
Get
Return
_ShippedRevenue
End
Get
Set
(
ByVal
value
As
Decimal
)
_ShippedRevenue = value
End
Set
End
Property
Protected
_ShippedRevenue
As
Decimal
= 0
Public
Property
OpenRevenue()
As
Decimal
Get
Return
_OpenRevenue
End
Get
Set
(
ByVal
value
As
Decimal
)
_OpenRevenue = value
End
Set
End
Property
Protected
_OpenRevenue
As
Decimal
= 0
Public
Property
Children()
As
ObservableCollection(Of CustomerOnTimeDeliveryPeriod)
Get
Return
_Children
End
Get
Set
(
ByVal
value
As
ObservableCollection(Of CustomerOnTimeDeliveryPeriod))
_Children = value
End
Set
End
Property
Protected
_Children
As
New
ObservableCollection(Of CustomerOnTimeDeliveryPeriod)
End
Class