This is a migrated thread and some comments may be shown as answers.

calling clearselections causes exception

2 Answers 66 Views
Chart
This is a migrated thread and some comments may be shown as answers.
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
David Ocasio asked on 31 Mar 2011, 06:55 PM

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

2 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 04 Apr 2011, 03:54 PM
Hello David Ocasio,

Thank you for contacting us.

Indeed we were able to reproduce the problematic behavior based on your guidelines and our developers will address the issue for the next weekly internal build (released each Monday).

For the time being as a workaround we would suggest you to manually clear the selection prior to rebinding the control:
void Button1_Click(object sender, RoutedEventArgs e)
{
    chartarea1.ClearSelection();
    chartYears.ItemsSource = new colCustomerOnTimeDelivery();
}

We have updated your Telerik points for the report as well.


Regards,
Giuseppe
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
answered on 04 Apr 2011, 04:19 PM
thanks Giuseppe
dco
Tags
Chart
Asked by
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Answers by
Giuseppe
Telerik team
David Ocasio
Top achievements
Rank 2
Iron
Veteran
Iron
Share this question
or