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

Data binding error to PieChart

2 Answers 148 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Doug
Top achievements
Rank 1
Doug asked on 18 Jul 2012, 09:09 AM
Hi,

I'm using version 2012.2.607.1050.

I have a data bound piechart with checkbox next to it. When i click the checkbox I then change the ItemSource collection. I have discovered that if the new collection has fewer points than the old collection i get an exception.

   at System.ThrowHelper.ThrowArgumentOutOfRangeException()
   at System.Collections.Generic.List`1.get_Item(Int32 index)
   at System.Collections.ObjectModel.Collection`1.get_Item(Int32 index)
   at Telerik.Windows.Controls.ChartView.ChartPalette.GetEntry(String family, Int32 index)
   at Telerik.Windows.Controls.ChartView.PieSeries.ApplyPaletteCore()
   at Telerik.Windows.Controls.ChartView.PresenterBase.ApplyPalette()
   at Telerik.Windows.Controls.ChartView.PresenterBase.UpdateUI(ChartLayoutContext context)
   at Telerik.Windows.Controls.ChartView.RadChartBase.UpdateUICore(ChartLayoutContext context)
   at Telerik.Windows.Controls.ChartView.PresenterBase.UpdateUI(ChartLayoutContext context)
   at Telerik.Windows.Controls.ChartView.RadChartBase.CallUpdateUI()
   at Telerik.Windows.Controls.ChartView.RadChartBase.OnInvalidated()

The xaml looks like this

   <telerik:RadPieChart Grid.Row="1" x:Name="FolderVersionsPieChart" Palette="Metro" >
                    <telerik:PieSeries ShowLabels="True" ItemsSource="{Binding VersionData}" >
                        <telerik:PieSeries.LabelDefinitions>
                            <telerik:ChartSeriesLabelDefinition Margin="-8,0,0,0">
                                <telerik:ChartSeriesLabelDefinition.Binding>
                                    <telerik:PropertyNameDataPointBinding PropertyName="Label" />
                                </telerik:ChartSeriesLabelDefinition.Binding>
                            </telerik:ChartSeriesLabelDefinition>
                        </telerik:PieSeries.LabelDefinitions>
                        <telerik:PieSeries.ValueBinding>
                            <telerik:PropertyNameDataPointBinding PropertyName="Value" />
                        </telerik:PieSeries.ValueBinding>
                    </telerik:PieSeries>
                </telerik:RadPieChart>

In the view model the collection is changed by setting new VersionData in the following method

 public ObservableCollection<DataPoint> VersionData
        {
            get { return _versionData; }
            set
            {
                _versionData = value;
                RaisePropertyChanged("VersionData");
            }
        }

The DataPoint class a simple string, value class

public class DataPoint
    {
        private double _value;
        private string _label;


        public double Value
        {
            get { return _value; }
            set { _value = value; }
        }


        public string Label
        {
            get { return _label; }
            set { _label = value; }
        }
    }

The only way I can get around this error is to populate the new collection with dummy zero DataPoint object values if the new collection has fewer DataPoint objects than the old collection. Then the new collection size will be the same size as the old one or larger. A bit ugly to say the least.

Am I doing something wrong here or is there another less hacky work around to fix this?

Thanks for your help
Doug

2 Answers, 1 is accepted

Sort by
0
Accepted
Rosko
Telerik team
answered on 20 Jul 2012, 08:02 AM
Hi Doug,

This is a known bug. The fix will be available for the next service pack release which is scheduled in one week.

All the best,
Rosko
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Doug
Top achievements
Rank 1
answered on 20 Jul 2012, 08:16 AM
Thanks Rosko.

Regards
Doug
Tags
ChartView
Asked by
Doug
Top achievements
Rank 1
Answers by
Rosko
Telerik team
Doug
Top achievements
Rank 1
Share this question
or