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

Quick question about databinding to manual data series

4 Answers 98 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Marcus Lambert
Top achievements
Rank 1
Marcus Lambert asked on 23 Nov 2009, 04:30 PM
Hi,
I am binding a List to a bar chart and defining a Series Mapping.
The problem I am having is that if I change the List in my ViewModel the chart seem to think that the it now has another series.
That is a nice feature but I dont want it to happen, is there a way to clear the orginal ?
Below is how I am binding ...

Thanks

 <Telerik_Windows_Controls:RadChart UseDefaultLayout="False" ItemsSource="{Binding BIStatEmailUsers, Mode=OneWay}" Grid.Row="4" d:LayoutOverrides="Width" Height="300" >
   <Telerik_Windows_Controls:RadChart.DefaultSeriesDefinition>
    <Telerik_Windows_Controls_Charting:HorizontalStackedBarSeriesDefinition/>
   </Telerik_Windows_Controls:RadChart.DefaultSeriesDefinition>
   <Telerik_Windows_Controls:RadChart.SeriesMappings>
    <Telerik_Windows_Controls_Charting:SeriesMapping ChartAreaName="TopInternalUsers">
     <Telerik_Windows_Controls_Charting:SeriesMapping.ItemMappings>
      <Telerik_Windows_Controls_Charting:ItemMapping FieldName="total"/>
      <Telerik_Windows_Controls_Charting:ItemMapping DataPointMember="XCategory" FieldName="lastname"/>
     </Telerik_Windows_Controls_Charting:SeriesMapping.ItemMappings>
    </Telerik_Windows_Controls_Charting:SeriesMapping>
   </Telerik_Windows_Controls:RadChart.SeriesMappings>
<Telerik_Windows_Controls:RadChart/>

4 Answers, 1 is accepted

Sort by
0
Dwight
Telerik team
answered on 26 Nov 2009, 07:58 AM
Hi Marcus,

This is a known issue. It is already fixed. Expect the service pack in the first half of December.

Best,
Evtim
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.
0
Nathan
Top achievements
Rank 2
answered on 18 Jan 2010, 06:30 PM
Hello,

Any update on this issue? I just updated to 2009.3.1314 (trial) and I still get similar results.

I am setting my itemsource in code, but when I do something like this I get duplicate charts:

 

 

RadChart1.ItemsSource = Nothing 
 
RadChart1.ItemsSource = oCol (observable collection I am binding to)  
 


Any update would be appreciated!

Thanks,
Nathan

 

 

 

 

0
Ves
Telerik team
answered on 21 Jan 2010, 09:36 AM
Hi Nathan,

I have attached a small example -- binding RadChart to observable collection. Can you please update it, so that the issue is reproduced?

Best regards,
Ves
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.
0
Nathan
Top achievements
Rank 2
answered on 21 Jan 2010, 03:40 PM
Hi Ves,

I did manage to recreate this issue, but at the same time found what I am doing wrong. When refreshing the chart, I not only have to clear the itemsource but also the seriesmappings since I am adding them dynamically in code - not in xaml.

So this replicates the duplication (commenting out the seriesmappings defined in xaml):
        private void LoadData()  
        {  
            RadChart1.ItemsSource = null;  
 
            SeriesMapping sm1 = new SeriesMapping();  
            sm1.CollectionIndex = 0;  
            sm1.SeriesDefinition = new BarSeriesDefinition();  
            sm1.LegendLabel = "My legend";  
 
            ItemMapping yMap = new ItemMapping("MyProperty", DataPointMember.YValue);  
            ItemMapping xMap = new ItemMapping("MyDescription", DataPointMember.XCategory);  
 
            sm1.ItemMappings.Add(yMap);  
            sm1.ItemMappings.Add(xMap);  
 
            RadChart1.SeriesMappings.Add(sm1);  
 
            ObservableCollection<ObservableCollection<MyObject>bindData = new ObservableCollection<ObservableCollection<MyObject>>();  
 
            data = new ObservableCollection<MyObject>()  
            {  
                new MyObject() {MyProperty=4MyDescription="Number A"},  
                new MyObject() {MyProperty=3MyDescription="Number B"},  
                new MyObject() {MyProperty=2,  MyDescription="Number C"},  
                new MyObject() {MyProperty=4,  MyDescription="Number D"}  
            };  
 
            bindData.Add(data);  
 
            RadChart1.ItemsSource = bindData;  
        } 

But if I do this when clearing out the old data it now works great!

 

            RadChart1.ItemsSource = null;  
            RadChart1.SeriesMappings.Clear(); 

This all makes sense since I am adding series mappings directly to the chart I would also have to remove them (or skip adding them again) on a refresh. Since the user can change the chart type (say from vertical to horizontal bar) I simply remove all series mappings
and rebuild the entire chart.

Thanks for the help (and the great controls)!

Tags
Chart
Asked by
Marcus Lambert
Top achievements
Rank 1
Answers by
Dwight
Telerik team
Nathan
Top achievements
Rank 2
Ves
Telerik team
Share this question
or