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

Itemmapping with fields of two different data structure

1 Answer 38 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Angshuman
Top achievements
Rank 2
Angshuman asked on 18 Nov 2010, 08:19 PM
I am trying to create a line chart, where the Itemmapping is done to two fields of a class and the RadControl.ItemSource is set to a List of objects of that class. The code is as follows:
SeriesMapping sm = new SeriesMapping();
            LineSeriesDefinition sd = new LineSeriesDefinition();
 
            sm.SeriesDefinition = sd;
 
            sm.ItemMappings.Add(new ItemMapping("Value",DataPointMember.YValue));
            sm.ItemMappings.Add(new ItemMapping("Time", DataPointMember.XValue));
            LineChart.SeriesMappings.Add(sm);
            LineChart.ItemsSource = GenerateLineData2(); // Returns a list of LineData objects ...

Here, the class that represents the data point looks as below

public class LineData
        {
            private double _time;
            private double _value;
            public double Time
            {
                get { return _time; }
                set { _time = value; }
            }           
            public double Value
            {
                get { return _value; }
                set { _value = value; }
            }
 
        }

The questions are
1. can I do ItemMapping if the fields 'Value' and 'Time' do not belong to the same class?
2. I have two lists of (say) double values, one for the 'Time' values and other for the 'Value' values; how can I perform the item mapping in that case?

1 Answer, 1 is accepted

Sort by
0
Evgeni "Zammy" Petrov
Telerik team
answered on 23 Nov 2010, 04:26 PM
Hello Angshuman,

 1. No, the data must come from the same object. You can of course wrap whatever business objects you have with a class and then use this class to expose the information to the chart.

2. You again need to wrap them in a class. 
Loop through Value and Time array and create a collection of LineData objects.

Regards,
Evgeni "Zammy" Petrov
the Telerik team
Browse the videos here>> to help you get started with RadControls for WPF
Tags
Chart
Asked by
Angshuman
Top achievements
Rank 2
Answers by
Evgeni "Zammy" Petrov
Telerik team
Share this question
or