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

Seperate Series from one Observable Collection Datasource

6 Answers 81 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Laura Edwards
Top achievements
Rank 1
Laura Edwards asked on 03 Aug 2010, 02:42 PM
Hi,

I have one chart that is bound to an observable collection in a viewmodel. The collection is made up of an array of seperate datapoints, that are grouped based on a property in the observable collection. Also, the collection is the result of a service call.

Right now, this results in a chart with one series with multiple lines on it of the same color.

Is there a way to make it where each of the arrays in the collection creates a seperate series on the chart?

6 Answers, 1 is accepted

Sort by
0
Accepted
Giuseppe
Telerik team
answered on 03 Aug 2010, 04:28 PM
Hello Laura,

We would suggest you to review this help article here that discusses data binding to nested collections.

Hope this helps.


Regards,
Freddie
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
Laura Edwards
Top achievements
Rank 1
answered on 03 Aug 2010, 07:18 PM
See my issue is that I am using MVVM and would like it if I didn't have to create the chart in the code behind. Is it possible to do it in the view of the chart?
0
Laura Edwards
Top achievements
Rank 1
answered on 04 Aug 2010, 03:45 PM
So the example you gave me will work, but I am using the view model pattern. Is there a way to access the radchart's name element in the seperate view model, or do I have to create the chart and do the nested collection binding in the view's code behind?
0
Giuseppe
Telerik team
answered on 04 Aug 2010, 04:17 PM
Hi Laura,

You can use the same approach from XAML with MVVM as well -- see the attached sample application to get you started.

Hope this helps.


Kind regards,
Freddie
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
Laura Edwards
Top achievements
Rank 1
answered on 04 Aug 2010, 05:34 PM
Thank you. I do like this way, but the chart won't display the series when bound to the nested collection.

this is my code:
<telerik:RadChart x:Name="PartnerDistributionChart" Grid.Row="2" Grid.Column="0" Grid.ColumnSpan="3" ItemsSource="{Binding Source={StaticResource ViewModel}, Path=BundleStatistics.DistributionStatistics}">
where bundlestatistics is the container collection and distributionstatistics is the collection nested in it.

if I use a foreach loop and break the distributionstatistics collection out and put it in it's own collection it works, but with all of the lines in one series and not broken up.
0
Giuseppe
Telerik team
answered on 06 Aug 2010, 03:35 PM
Hello Laura,

Please review the sample application we attached in our previous reply -- RadChart.ItemsSource should be set to the container collection, and SeriesMapping.CollectionIndex property should be set to the respective nested collection index for each nested collection that you would like to display in the control:

<telerik:RadChart x:Name="RadChart1" ItemsSource="{Binding Data}">
 
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping CollectionIndex="0">
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:LineSeriesDefinition />
            </telerik:SeriesMapping.SeriesDefinition>
             
            <telerik:ItemMapping FieldName="YValue" DataPointMember="YValue" />
        </telerik:SeriesMapping>
        <telerik:SeriesMapping CollectionIndex="1">
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:LineSeriesDefinition />
            </telerik:SeriesMapping.SeriesDefinition>
             
            <telerik:ItemMapping FieldName="YValue" DataPointMember="YValue" />
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
 
</telerik:RadChart

Let us know if we are missing something out.


Kind regards,
Freddie
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
Tags
Chart
Asked by
Laura Edwards
Top achievements
Rank 1
Answers by
Giuseppe
Telerik team
Laura Edwards
Top achievements
Rank 1
Share this question
or