SeriesMapping not working - data duplicated

3 posts, 0 answers
  1. Brian
    Brian avatar
    45 posts
    Member since:
    May 2008

    Posted 12 Feb 2010 Link to this post


    I'm populating a radChart using a WCF service call that returns two fields: fiscal_year (int) and bd_rev_annual (money).  If I load the chart simply by setting the ItemsSource to the result of method GetBudgetsByYearAsync() (not calling procedure ConfigureBudgetChart) then the chart displays as expected.  However, if I call procedure ConfigureBudgetChart before assigning the ItemsSource the data in the chart is duplicated (two bars instead of one for each fiscal year) and the datapointMember X values still display as (0,1,2) rather than (2008, 2009, 2010) as I would expect...

    Also you'll note in the xaml code at the end that the radChart tag displays as <my:RadChart> rather than <telerikChart:RadChart> as would be expected...I have made the correct references so am not sure why this is happening...

    This is the first time I've tried anything with Silverlight so am not too sure what's going on - any help would be greatly appreciated



    Imports System
    Imports System.Collections.Generic
    Imports Microsoft.VisualBasic
    Imports System.Linq
    Imports System.Net
    Imports System.Windows
    Imports System.Windows.Controls
    Imports System.Windows.Documents
    Imports System.Windows.Input
    Imports System.Windows.Media
    Imports System.Windows.Media.Animation
    Imports System.Windows.Shapes
    Imports Telerik.Windows.Controls.Charting

    Imports freebalanceSilverlight.FreebalanceSvc

    Partial Public Class MainPage
        Inherits UserControl

        Public Sub New()

            AddHandler Loaded, AddressOf MainPage_Loaded

        End Sub

        Private Sub MainPage_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded

            Dim proxy As FreebalanceSvc.FreebalanceServiceClient = New FreebalanceSvc.FreebalanceServiceClient

            AddHandler proxy.GetBudgetsByYearCompleted, AddressOf proxy_GetBudgetByYearCompleted

        End Sub

        Private Sub proxy_GetBudgetByYearCompleted(ByVal sender As Object, ByVal e As FreebalanceSvc.GetBudgetsByYearCompletedEventArgs)

            Me.chart1.ItemsSource = e.Result

        End Sub

        Private Sub ConfigureBudgetChart()

            Me.chart1.DefaultView.ChartArea.AxisX.Title = "Fiscal Years"
            Me.chart1.DefaultView.ChartArea.AxisY.Title = "Dollars"

            Dim seriesMapping As New SeriesMapping()
            seriesMapping.LegendLabel = "Budget"
            seriesMapping.SeriesDefinition = New BarSeriesDefinition

            seriesMapping.ItemMappings.Add(New ItemMapping("fiscal_year", DataPointMember.XValue))
            seriesMapping.ItemMappings.Add(New ItemMapping("bd_rev_annual", DataPointMember.YValue))


        End Sub

    End Class


    <UserControl xmlns:telerikNavigation="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Navigation"  xmlns:telerikInput="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Input"  xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"  x:Class="freebalanceSilverlight.MainPage"
        xmlns:d="" xmlns:mc="" 
        mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480">
      <Grid x:Name="LayoutRoot" Background="White">
            <my:RadChart x:Name="chart1">
  2. Velin
    Velin avatar
    391 posts

    Posted 17 Feb 2010 Link to this post

    Hello Brian,

    First of all you should make sure that the SeriesMapping collection of the chart control is cleared whenever the ConfigureBudgetChart method is invoked. The best way to do this will be to add the following line of code at the beginning of the method body:

    This should be enough to prevent visual duplication of the data.

    To use telerikChart as namespace for the chart control you should change the following namespace declaration 

    Hope this will help.

    All the best,
    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.
  3. Brian
    Brian avatar
    45 posts
    Member since:
    May 2008

    Posted 17 Feb 2010 Link to this post

    Thank you for the reply - I actually realized that I had two problems...

    To resolve the duplication issue I removed the handler that I had added to the New() procedure:

    AddHandler Loaded, AddressOf MainPage_Loaded

    Regarding the DataPointMember.XCategory values - I had changed the field names in my stored procedure but not in my application, so once I made that change the correct values were displayed.

    Regarding the namespace declaration for the chart, by default when I drag it on to the xaml page it uses 'xmlns:my' and it works without changing it to 'xmlns:telerikChart' - I just wasn't sure why that was happening...

    Anyways, everything seems to be working as expected now


Back to Top