ItemsSource not updating with stacked series.

5 posts, 0 answers
  1. Rex Walker
    Rex Walker avatar
    7 posts
    Member since:
    Oct 2009

    Posted 10 Nov 2009 Link to this post

    I’ve noticed that when I change the ItemsSource on a RadChart that uses StatckedAreaSeries (in this case) that instead of the graph display being replaced with new data, it simply adds the new series.

    So what happens is that instead of graphing 2 values, it shows 4, if I update again, it shows 6.

    Here is some sample Xaml and VB code I put together just to show what is happening.  Each time the Update button is hit, the values are added as a new set of dataseries rather than replacing the data used by the current data series.

    This is not the exact code that I use and I have a few more data series and mixed types (StackedBar, Area, etc...).    This just shows what I'm experiencing when updating the ItemsSource.   I've tried various collections, lists, etc...  I can't seem to find a way to clear the current data.

    MainPage.xaml

    <UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                 xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
                 xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
                 mc:Ignorable="d" 
                 xmlns:Telerik_Windows_Controls="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting" 
                 xmlns:Telerik_Windows_Controls_Charting="clr-namespace:Telerik.Windows.Controls.Charting;assembly=Telerik.Windows.Controls.Charting" 
                 x:Class="RadChartItemsSource.MainPage" 
                 d:DesignWidth="640" 
                 d:DesignHeight="480">  
        <Grid x:Name="LayoutRoot">  
     
            <Grid.RowDefinitions> 
                <RowDefinition Height="Auto" /> 
                <RowDefinition Height="*" /> 
            </Grid.RowDefinitions> 
     
            <Telerik_Windows_Controls:RadChart x:Name="radChart1" 
                                               Grid.Row="1" 
                                               VerticalAlignment="Stretch" 
                                               HorizontalAlignment="Stretch" 
                                               Margin="0,0,0,0" 
                                               UseDefaultLayout="False" 
                                               Visibility="Visible">  
     
                <Telerik_Windows_Controls:RadChart.SeriesMappings> 
                    <Telerik_Windows_Controls_Charting:SeriesMapping x:Name="sDataValueSeriesMap" 
                                                                     ChartAreaName="sDataValueArea" 
                                                                     LegendLabel="Success">  
     
                        <Telerik_Windows_Controls_Charting:SeriesMapping.SeriesDefinition> 
     
                            <Telerik_Windows_Controls_Charting:StackedAreaSeriesDefinition x:Name="sDataValueSeriesDef" 
                                                                                           ShowItemLabels="False" 
                                                                                           ShowPointMarks="False" /> 
                        </Telerik_Windows_Controls_Charting:SeriesMapping.SeriesDefinition> 
     
     
                        <Telerik_Windows_Controls_Charting:SeriesMapping.ItemMappings> 
                            <Telerik_Windows_Controls_Charting:ItemMapping x:Name="sDataValueItemMap" 
                                                                           FieldName="DataValue" 
                                                                           DataPointMember="YValue">  
                            </Telerik_Windows_Controls_Charting:ItemMapping> 
     
                            <Telerik_Windows_Controls_Charting:ItemMapping x:Name="sDataValueItemMapDate" 
                                                                           FieldName="MyOADate" 
                                                                           DataPointMember="XValue" /> 
     
                        </Telerik_Windows_Controls_Charting:SeriesMapping.ItemMappings> 
                    </Telerik_Windows_Controls_Charting:SeriesMapping> 
     
                    <Telerik_Windows_Controls_Charting:SeriesMapping x:Name="sDataValueOtherSeriesMap" 
                                                                     ChartAreaName="sDataValueArea" 
                                                                     LegendLabel="Success">  
     
                        <Telerik_Windows_Controls_Charting:SeriesMapping.SeriesDefinition> 
     
                            <Telerik_Windows_Controls_Charting:StackedAreaSeriesDefinition x:Name="sDataValueOtherSeriesDef" 
                                                                                           ShowItemLabels="False" 
                                                                                           ShowPointMarks="False" /> 
                        </Telerik_Windows_Controls_Charting:SeriesMapping.SeriesDefinition> 
     
     
                        <Telerik_Windows_Controls_Charting:SeriesMapping.ItemMappings> 
                            <Telerik_Windows_Controls_Charting:ItemMapping x:Name="sDataValueOtherItemMap" 
                                                                           FieldName="DataValueOther" 
                                                                           DataPointMember="YValue">  
                            </Telerik_Windows_Controls_Charting:ItemMapping> 
     
                            <Telerik_Windows_Controls_Charting:ItemMapping x:Name="sDataValueOtherItemMapDate" 
                                                                           FieldName="MyOADate" 
                                                                           DataPointMember="XValue" /> 
     
                        </Telerik_Windows_Controls_Charting:SeriesMapping.ItemMappings> 
                    </Telerik_Windows_Controls_Charting:SeriesMapping> 
     
                </Telerik_Windows_Controls:RadChart.SeriesMappings> 
     
                <Grid x:Name="sDataValueChartGrid" 
                      HorizontalAlignment="Stretch" 
                      VerticalAlignment="Stretch">  
                    <Grid.RowDefinitions> 
                        <RowDefinition Height="Auto" /> 
                        <RowDefinition Height="*" /> 
                    </Grid.RowDefinitions> 
     
                    <Telerik_Windows_Controls_Charting:ChartArea x:Name="sDataValueArea" 
                                                                 Grid.Row="1" 
                                                                 EnableAnimations="False">  
     
                        <Telerik_Windows_Controls_Charting:ChartArea.AxisX> 
                            <Telerik_Windows_Controls_Charting:AxisX x:Name="sDataAxisX" 
                                                                     LabelRotationAngle="67" 
                                                                     Title="ThisTitle" 
                                                                     LayoutMode="Inside" 
                                                                     StripLinesVisibility="Collapsed" 
                                                                     TicksDistance="24" 
                                                                     IsDateTime="True" 
                                                                     AutoRange="True" 
                                                                     DefaultLabelFormat="YYYY-MMM-dd HH:mm:ss" 
                                                                     MajorGridLinesVisibility="Visible">  
     
                            </Telerik_Windows_Controls_Charting:AxisX> 
                        </Telerik_Windows_Controls_Charting:ChartArea.AxisX> 
     
                        <Telerik_Windows_Controls_Charting:ChartArea.AxisY> 
                            <Telerik_Windows_Controls_Charting:AxisY x:Name="sDataAxisY" 
                                                                     Title="Scale" 
                                                                     ExtendDirection="None" 
                                                                     StripLinesVisibility="Collapsed" 
                                                                     MajorGridLinesVisibility="Visible" 
                                                                     MinorGridLinesVisibility="Visible">  
                            </Telerik_Windows_Controls_Charting:AxisY> 
                        </Telerik_Windows_Controls_Charting:ChartArea.AxisY> 
     
                    </Telerik_Windows_Controls_Charting:ChartArea> 
     
                </Grid> 
     
     
            </Telerik_Windows_Controls:RadChart> 
     
            <Button Grid.Row="0" 
                    x:Name="UpdateChart" 
                    HorizontalAlignment="Center" 
                    Content="Update" 
                    Height="45" 
                    Width="100">  
            </Button> 
     
        </Grid> 
    </UserControl> 
     

     
    MainPage.xaml.vb

    Imports System.ComponentModel  
    Imports System.Collections.ObjectModel  
     
    Partial Public Class MainPage  
        Inherits UserControl  
     
        'Tried using observable collection, no change.  
        'Private _tmpList As ObservableCollection(Of TestItem)  
        Public Sub New()  
            InitializeComponent()  
        End Sub 
     
        Private Sub UpdateChart_Click(ByVal sender As ObjectByVal e As System.Windows.RoutedEventArgs) Handles UpdateChart.Click  
            '----  
            'Tried using a local collection, clearing it, etc..  Didn't change.  
            '----  
            'If IsNothing(_tmpList) Then  
            '    _tmpList = New ObservableCollection(Of TestItem)  
            'Else  
            '    _tmpList.Clear()  
            'End If  
            'radChart1.ItemsSource = Nothing  
     
            Dim TmpList As New List(Of TestItem)  
            For i As Integer = 1 To 10  
                TmpList.Add(New TestItem(i, i * 2, DateTime.Now.AddDays(i)))  
            Next 
            radChart1.ItemsSource = TmpList  
        End Sub 
    End Class 
     
    ''' <summary>  
    ''' Test class containing data values and date for chart  
    ''' </summary>  
    ''' <remarks></remarks>  
    Public Class TestItem  
        Implements INotifyPropertyChanged  
     
     
        Private _DataValue As Double 
        Public Property DataValue() As Double 
            Get 
                Return _DataValue  
            End Get 
            Set(ByVal value As Double)  
                _DataValue = value  
                PropChanged("DataValue")  
            End Set 
        End Property 
     
        Private _DataValueOther As Double 
        Public Property DataValueOther() As Double 
            Get 
                Return _DataValueOther  
            End Get 
            Set(ByVal value As Double)  
                _DataValueOther = value  
                PropChanged("DataValueOther")  
            End Set 
        End Property 
     
     
        Public ReadOnly Property MyOADate() As Double 
            Get 
                Return ItemDate.ToOADate  
            End Get 
        End Property 
     
     
     
        Private _ItemDate As DateTime  
        Public Property ItemDate() As DateTime  
            Get 
                Return _ItemDate  
            End Get 
            Set(ByVal value As DateTime)  
                _ItemDate = value  
                PropChanged("ItemDate")  
                PropChanged("MyOADate")  
            End Set 
        End Property 
     
     
     
        Public Event PropertyChanged(ByVal sender As ObjectByVal e As System.ComponentModel.PropertyChangedEventArgs) Implements System.ComponentModel.INotifyPropertyChanged.PropertyChanged  
        Private Sub PropChanged(ByVal PropName As String)  
            RaiseEvent PropertyChanged(MeNew PropertyChangedEventArgs(PropName))  
        End Sub 
     
        Public Sub New(ByVal pValue As DoubleByVal pDataValueOther As DoubleByVal pDate As DateTime)  
            ItemDate = pDate  
            DataValue = pValue  
            DataValueOther = pDataValueOther  
        End Sub 
    End Class 

     

  2. Rex Walker
    Rex Walker avatar
    7 posts
    Member since:
    Oct 2009

    Posted 11 Nov 2009 Link to this post

    I forgot to mention that I am running version 2009.3.1103.1030 of the SL controls.

    Working sample using the exact code provided in my previous message is available here:
    http://www.rge-inc.com/sl/default.html

    We start with no data.
    Click the Update button just to update the items source with a new set of data.

    The expected action is no change to the chart since the data is virtually identical.

  3. DevCraft banner
  4. Rex Walker
    Rex Walker avatar
    7 posts
    Member since:
    Oct 2009

    Posted 13 Nov 2009 Link to this post

    Just wanted to update that I did find a workaround.

    Even though clearing the ItemsSource associated with the RadChart by either setting it to null or replacing it causes the graph to generate additional series when it is replaced, the final solution is a little weird.

    While this Doesn't Work
    radChart1.ItemsSource = Nothing  <has no effect>

    This Does Work
    sDataValueArea.DataSeries.Clear() <clears the chart to prep for new data>
    (where sDataValueArea is a ChartArea within the chart definition).

    Is there a possbility in a future version that if the ItemsSource of the main chart is cleared, it effectively clears the associated ChartArea DataSeries as well? 

    Thanks...
    I think I'm good now on this issue..

  5. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 16 Nov 2009 Link to this post

    Hi Rex,

    Indeed we were able to reproduce the problem and unfortunately we must confirm it is a bug within the RadChart control -- the series are not properly cleared on rebind when non-default chart layout is used (UseDefaultLayout = false).

    We will log this issue in our bugtracking system and will forward it to our developers so they can address it for the official service pack release (~ first half of December). For the time being we would suggest you to use the workaround you have already discovered on your own.

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


    Best wishes,
    Manuel
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  6. Marcus Lambert
    Marcus Lambert avatar
    41 posts
    Member since:
    Aug 2009

    Posted 24 Nov 2009 Link to this post

    Hi,
     I have hit this for horizontal bar as well.
    Clearling the dataseries is a workaround if you are using code behind, it is more of a problem when you are using MVVM.
    The way i have been doing it is trap the binding event on the chart and then clear the DataSeries.
    Marcus
Back to Top
DevCraft banner