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

Bind to an ObservableCollection of ObservableCollections

5 Answers 201 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Andy
Top achievements
Rank 1
Andy asked on 28 Jul 2009, 11:52 AM
Hi Guys

I am trying to bind my chart to a ObservableCollection of ObservableCollections is this possible?

I have worked look at ms-help://telerik.windows.controls/telerik.windows.controls.charting/data-binding-series-mappings.html but no joy. Do you have a sample of this in VB ?

5 Answers, 1 is accepted

Sort by
0
Vladimir Milev
Telerik team
answered on 31 Jul 2009, 12:55 PM
Hi Andy,

Please check this blog post. The code is in C#, however, it is minimal and you can use our converter to translate it to VB.

Greetings,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Andy
Top achievements
Rank 1
answered on 19 Aug 2009, 09:23 AM
Thanks guys for you help in this, i now have it working.

However if i have my chart bound to an ObservableCollection of ObservableCollections and another ObservableCollection is added the chart will not display the extra Series as There are no Series Mappings set up. Consider the following code

Dim

 

m1 As New SeriesMapping()

 

 

Dim m2 As New SeriesMapping()

 

m1.CollectionIndex = 0

m1.SeriesDefinition =

New LineSeriesDefinition

 

m2.CollectionIndex = 1

m2.SeriesDefinition =

New LineSeriesDefinition

 

 

Dim im1 As New ItemMapping

 

im1.DataPointMember = DataPointMember.YValue

 

Dim im2 As New ItemMapping

 

im2.DataPointMember = DataPointMember.YValue

m1.ItemMappings.Add(im1)

m2.ItemMappings.Add(im2)

NextPage.RadChart1.SeriesMappings.Add(m1)

NextPage.RadChart1.SeriesMappings.Add(m2)

 

NextPage.RadChart1.ItemsSource = MyData

How if a new data Series is added to MyData the chart only displays the first 2 series how can i make it display all automaticaly

 

0
Vladimir Milev
Telerik team
answered on 25 Aug 2009, 08:35 AM
Hello Andy,

This not available out-of-the-box. You will need to manually update your mappings.
We apologize for the inconvenience.

Kind regards,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Anthony Daniel
Top achievements
Rank 1
answered on 09 Dec 2009, 06:27 PM
I'm able to add a new series and a new seriesmapping to my chart, but it is rendering the datapoints of each new series at y=0.  I'm testing with teh DatBinding example chart and have setup the itemssource to be a List<List<DataClass>> with a single series to start with.

private void Button_Click(object sender, RoutedEventArgs e)
        {
            Random rand = new Random(DateTime.Now.Millisecond);
            
            List<List<DataClass>> ccSource = this.RadChart1.ItemsSource as List<List<DataClass>>;
            List<DataClass> newSeries = new List<DataClass>();
            for(int idx = 0; idx < 5; idx++)
            {
                newSeries.Add(new DataClass(RandomDataGenerator.GetRounedDoubleValue(),RandomDataGenerator.GetRounedDoubleValue(),"test"));
            }
            ccSource.Add(newSeries);

            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.SeriesDefinition = new LineSeriesDefinition();
            seriesMapping.CollectionIndex = ccSource.Count - 1;
            ItemMapping itemMapping = new ItemMapping();
            itemMapping.DataPointMember = DataPointMember.YValue;
            itemMapping.FieldName = "Data.DoubleData2"; //same field name used when setting up the initial itemmapping (which works)
            seriesMapping.ItemMappings.Add(itemMapping);
            this.RadChart1.SeriesMappings.Add(seriesMapping);
        }

0
Velin
Telerik team
answered on 11 Dec 2009, 02:29 PM
Hi Anthony Daniel,

 You should bind your chart to an ObservableCollection<ObservableCollection<T>> in order to get collection change notifications which the chart control handles and updates the data series. Please find attached a small example demonstrating this approach.

Hope this will help.


All the best,
Velin
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.
Tags
Chart
Asked by
Andy
Top achievements
Rank 1
Answers by
Vladimir Milev
Telerik team
Andy
Top achievements
Rank 1
Anthony Daniel
Top achievements
Rank 1
Velin
Telerik team
Share this question
or