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

SeriesMapping not working - data duplicated

2 Answers 58 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 12 Feb 2010, 04:13 PM
Hi

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

Thanks,

Brian

--------------------------------------------------------------------
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()

        InitializeComponent()
        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
        proxy.GetBudgetsByYearAsync()

    End Sub

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

        ConfigureBudgetChart()
        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))

        chart1.SeriesMappings.Add(seriesMapping)

    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="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" d:DesignWidth="640" d:DesignHeight="480">
  <Grid x:Name="LayoutRoot" Background="White">
      
        <my:RadChart x:Name="chart1">
        </my:RadChart>
      
        <telerikNavigation:RadCoverFlow></telerikNavigation:RadCoverFlow>
        <telerikInput:RadComboBox></telerikInput:RadComboBox>
      
  </Grid>
</UserControl>
--------------------------------------------------------------------

2 Answers, 1 is accepted

Sort by
0
Velin
Telerik team
answered on 17 Feb 2010, 12:47 PM
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:
chart1.SeriesMappings.Clear()

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 
xmlns:my="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"
to
xmlns:telerikChart="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.Charting"


Hope this will help.

All the best,
Velin
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
Brian
Top achievements
Rank 1
answered on 17 Feb 2010, 01:42 PM
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

Thanks,

Brian
Tags
Chart
Asked by
Brian
Top achievements
Rank 1
Answers by
Velin
Telerik team
Brian
Top achievements
Rank 1
Share this question
or