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

One DataSource,Many SeriesMappings

3 Answers 74 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Kelley Wong
Top achievements
Rank 1
Kelley Wong asked on 08 Mar 2011, 09:32 AM
I have a datasource like this(the PCName is variational)

Year             PCName               Price
2009             Dell                       100
2009             Lenovo                  95.4
2009             ASUS                    85
2008             Dell                      130
2008            Lenovo                 75.4
2008            ASUS                     81.5
2010            Dell                       95.0
2010            Lenovo                 95.4
2010            ASUS                    97

ChartControl.SeriesMappings.Clear();
SeriesMapping BarMapping = new SeriesMapping();
BarSeriesDefinition BarDefinition = new BarSeriesDefinition();
BarDefinition.ShowItemLabels = true;
BarDefinition.ShowItemToolTips = true;
BarDefinition.LabelSettings.ShowZeroValueLabels = false;
BarLabelSettings BarLabelSettings = new BarLabelSettings(LabelDisplayMode.MidPoint);
BarLabelSettings.ShowZeroValueLabels = false;
BarDefinition.LabelSettings = BarLabelSettings;
BarMapping.SeriesDefinition = BarDefinition;
BarMapping.ItemMappings.Add(new ItemMapping("Price", DataPointMember.YValue));
BarMapping.ItemMappings.Add(new ItemMapping("Year", DataPointMember.XCategory));
BarMapping.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor("PCName"));
ChartControl.SeriesMappings.Add(BarMapping);

i set the SeriesMappings or chart control code behind above,and it works fine!

But now i want to set different SeriesMapping ,  first year data use BarSeriesDefinition ,and second year data use  LineSeriesDefinition ,third year another ,forth another

can i do it code behind use the same datasource

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 10 Mar 2011, 09:43 PM
Hello Kelley Wong,

You can set multiple SeriesMappings that use the same data from the ItemsSource. Each series mapping will create a new series for your chart. You can take a look on Grouping and Aggregation online demo here that uses similar approach.

Best regards,
Yavor Ivanov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Kelley Wong
Top achievements
Rank 1
answered on 11 Mar 2011, 02:14 AM
in clearly ,i want to set the 2009 data use BarSeriesDefinition ,and 2010 data use LineSeriesDefinition and 2008 data use another series in one chart
0
Accepted
Yavor
Telerik team
answered on 15 Mar 2011, 12:16 PM
Hi Kelley Wong,

You can try filtering your data by the year field and displaying your data with PCname as XCategory. The code for creating the series mappings can look like this:

// Bar series (2009)
SeriesMapping BarMapping = new SeriesMapping() { LegendLabel = "2009" };
BarMapping.SeriesDefinition = new BarSeriesDefinition()
{
    ShowItemLabels = true,
    ShowItemToolTips = true,
    LabelSettings = new BarLabelSettings(LabelDisplayMode.MidPoint) { ShowZeroValueLabels = false }
};
CreateItemMappings(BarMapping.ItemMappings);
FilterData(BarMapping, 2009);
 
collection.Add(BarMapping);
 
// line series (2010)
SeriesMapping LineMapping = new SeriesMapping() { LegendLabel = "2010" };
LineMapping.SeriesDefinition = new LineSeriesDefinition()
{
    ShowItemLabels = true,
    ShowItemToolTips = true
};
CreateItemMappings(LineMapping.ItemMappings);
FilterData(LineMapping, 2010);
 
collection.Add(LineMapping);
 
// line series (2008)
SeriesMapping LineMapping2 = new SeriesMapping() { LegendLabel = "2008" };
LineMapping2.SeriesDefinition = new LineSeriesDefinition()
{
    ShowItemLabels = true,
    ShowItemToolTips = true
};
CreateItemMappings(LineMapping2.ItemMappings);
FilterData(LineMapping2, 2008);
 
collection.Add(LineMapping2);

Filtering data can be achieved by using RadChart build-in filtering functionality. Here is the sample code:
private void FilterData(SeriesMapping mapping, int year)
{
    mapping.FilterDescriptors.Add(new ChartFilterDescriptor("Year", typeof(Int32), Telerik.Windows.Data.FilterOperator.IsEqualTo, year));
}

Finally here is the code for mapping your data to your series:
private void CreateItemMappings(ItemMappingCollection collection)
{
    collection.Add(new ItemMapping("Price", DataPointMember.YValue));
    collection.Add(new ItemMapping("PCName", DataPointMember.XCategory));
}

You can find all of the above code in the attached files.

Hope this helps!


All the best,
Yavor Ivanov
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
Chart
Asked by
Kelley Wong
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Kelley Wong
Top achievements
Rank 1
Share this question
or