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

Line Series on Complex Type

2 Answers 25 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Guillaume
Top achievements
Rank 1
Guillaume asked on 02 Feb 2011, 03:17 PM
Hello,

I try to use the chart with Line serie on a collection of a complex type.

In my ViewModel, i have an ObservableCollection<NumerizationOperatorByDate> OperatorsByDate with that :
public class NumerizationOperatorByDate
    {
        public string FullName { get; set; }
 
        public List<NumerizationFoldersByDate> NbFoldersProcessedByDate { get; set; }
   }
 
public class NumerizationFoldersByDate : ReturnObject
    {
        public DateTime Date { get; set; }
 
        public int NbFoldersProcessed { get; set; }
    }

Ok and in my View, i have that :
<telerik:RadChart ItemsSource="{Binding OperatorsByDate}"
                                                      Content=""
                                                      BorderBrush="Black"
                                                      Width="400"
                                                      Height="300"
                                                      BorderThickness="0"
                                                      d:LayoutOverrides="HorizontalMargin">
                                        <telerik:RadChart.SeriesMappings>
                                            <telerik:SeriesMapping>
                                                <telerik:SeriesMapping.SeriesDefinition>
                                                    <telerik:LineSeriesDefinition />
                                                </telerik:SeriesMapping.SeriesDefinition>
                                                <telerik:ItemMapping DataPointMember="XValue"
                                                                     FieldName="NbFoldersProcessedByDate.Date />
                                                <telerik:ItemMapping DataPointMember="YValue"
                                                                     FieldName="NbFoldersProcessedByDate.NbFoldersProcessed />
                                            </telerik:SeriesMapping>
                                        </telerik:RadChart.SeriesMappings>
                                        <telerik:RadChart.DefaultView>
                                            <telerik:ChartDefaultView ChartLegendPosition="Bottom">
                                                <telerik:ChartDefaultView.ChartArea>
                                                    <telerik:ChartArea SmartLabelsEnabled="true"
                                                                       Margin="0 />
                                                </telerik:ChartDefaultView.ChartArea>
                                                <telerik:ChartDefaultView.ChartLegend>
                                                    <telerik:ChartLegend Visibility="Collapsed />
                                                </telerik:ChartDefaultView.ChartLegend>
                                            </telerik:ChartDefaultView>
                                        </telerik:RadChart.DefaultView>
                                    </telerik:RadChart>

In fact, i want a line for each NumerizationOperator and in X axis, DateTimes and in Y axis, int.

Where i'm wrong ?

Best regards,
Guillaume

2 Answers, 1 is accepted

Sort by
0
Guillaume
Top achievements
Rank 1
answered on 03 Feb 2011, 12:01 PM
Re,

I downloaded your example and opened it. As you, i created a dep property of type SeriesMappingCollection and copied the InitializeLineChartSeriesMappings but in the code, when you pass the field name (in CreateSeriesMapping) :

result.ItemMappings.Add(new ItemMapping("Date", DataPointMember.XCategory));

I can't do the same thing, because my property is in the sub object of my class : according to my object model above :
NumerizationOperatorByDate > NbFoldersProcessedByDate > Date

So, if i do that :

result.ItemMappings.Add(new ItemMapping("NbFoldersPrcessedByDate.Date", DataPointMember.XCategory));

I have a NullReferenceException when the OnPropertyChanged on the dep property SeriesMappingCollection.

Can you help me ? Because i think it's not possible to target a sub property.

Best Regards,
Guillaume

0
Evgenia
Telerik team
answered on 07 Feb 2011, 02:59 PM
Hello Guillaume,

I understand your scenario, but first let me explain a little bit more on how RadChart creates series from the data in the ItemsSource. To support complex scenarios RadChart introduces the SeriesMapping object. This non-visual element describes how the underlying data from the ItemsSource has to be mapped to the series. As you may want your series to be mapped differently, you have to add a SeriesMapping object for every series that you want to display on the screen.

Currently RadChart's support for nested collections requires your seriesmapping to have collection index (described in our help topic) and the data for this mapping to be available in the underlying collection on the specified index like in the image below:

If you remove the IEnumerable implementation of your business object the data for the series will be accessible through the Data property like in the image below:


Currently RadChart SeriesMappings do not support such type of binding, but this feature is planned for Q1 of 2011. When this feature is available you will be able to configure ItemsSource per SeriesMapping.

You can find a sample project attached that represents the scenario you have.

Regards,
Evgenia
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
Chart
Asked by
Guillaume
Top achievements
Rank 1
Answers by
Guillaume
Top achievements
Rank 1
Evgenia
Telerik team
Share this question
or