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

[Solved] Binding to dictionary<int, ObservableCollection<T>>

1 Answer 173 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Jeremy
Top achievements
Rank 1
Jeremy asked on 15 Feb 2011, 06:02 PM
I am trying to create a RadChart that has a line series for each collection contained in a dictionary.  I have looked at the "Binding to Nested Collections" example and tried setting the CollectionIndex of the SeriesMapping to the integer key used by dictionary but I get an ArgumentOutOfRange exception when I set the charts Itemsource.  I also tried just setting it to 0 when there is a single collection in the dictionary but no change.

This is what I am trying to bind to:

public Dictionary<int, ObservableCollection<PubSubServiceProxy.TimestampedDouble>> Data
        { get; set; }

This is the code that adds the series.  tagId is a key into the dictionary.

void AddSeries(string name, int tagId)
{
    try
    {
        var seriesMapping = new SeriesMapping();
        seriesMapping.SeriesDefinition = new LineSeriesDefinition();
        seriesMapping.SeriesDefinition.SeriesName = name;
        seriesMapping.SeriesDefinition.ShowItemLabels = false;
        seriesMapping.SeriesDefinition.ShowItemToolTips = false;
        seriesMapping.ItemMappings.Add(new ItemMapping("Timestamp", DataPointMember.XValue));
        seriesMapping.ItemMappings.Add(new ItemMapping("Value", DataPointMember.YValue));
        seriesMapping.CollectionIndex = tagId;
        chart.SeriesMappings.Add(seriesMapping);
        chart.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "mm:ss.fff";
        chart.DefaultView.ChartArea.AxisX.LabelRotationAngle = 45;
        chart.ItemsSource = _viewModel.Data;
    }
    catch (Exception ex)
    {
        throw;
    }
}

Can someone tell me what I am doing wrong?  I'm still a trial user and would like to make sure that this works before I purchase the controls.  Thanks.

1 Answer, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 21 Feb 2011, 09:09 AM
Hi Jeremy,

Your question was answered in the Support thread started from you (Ticket ID: 394656).
As a side note - please choose one of the threads(Forum or Support) so that it's easier for me and you to follow the correspondence.

Best wishes,
Evgenia
the Telerik team
Tags
Chart
Asked by
Jeremy
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
Share this question
or