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

ItemMapping for Dictionary

7 Answers 154 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Evan
Top achievements
Rank 1
Evan asked on 14 Oct 2009, 09:06 PM
I have a RadGrid that shows a variable number of columns based on user input.  I did this by having a Dictionary property on the bound object and setting a custom Binding object for the GridViewDataColumn.DataMemberBinding property.  It works great.  It looks like the ItemMapping object for the RadChart is not as flexible.  Do I have to have a property for every ItemMapping I add to the SeriesMapping?  Is there any other way to create a ItemMapping for a Dictionary property?

7 Answers, 1 is accepted

Sort by
0
Vladimir Milev
Telerik team
answered on 20 Oct 2009, 05:49 AM
Hello Evan Wang,

Generally speaking each SeriesMapping you add creates a new DataSeries after data binding completes. RadChart creates a DataPoint for each record in the data source and maps all properties from the business object based on the ItemMapping. What kind of scenario are you trying to achieve? What is your data? In RadChart we do not have a concept of "Auto Generated colums" but then again it is not something that applies to a chart control.

Please, let us know your data and how you would like to data bind your chart and I will let you know what is the best way to do it.

Sincerely yours,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Evan
Top achievements
Rank 1
answered on 22 Oct 2009, 01:25 PM
My grid has a variable number of columns depending on user input.  My bound object has some properties that will always be in the grid plus a Dictionary with a bunch of key/values representing the variable columns.  I used an example I found on this website that uses a Binding object and DictionaryConverter (IValueConverter) for the unknown columns.  This works great for the grid, but not for the chart.  I also just noticed and posted created another thread where I'm having problems with the Binding object and grid.ToHtml().  Is the Binding object not the best way to display data in the grid?

I ended up looping through my List of objects and creating DataSeries with manually added DataPoints.  This works fine, but is not the most elegant solution.  Do you have any other suggestions?
0
Vladimir Milev
Telerik team
answered on 28 Oct 2009, 08:16 AM
Hello Evan Wang,

Can you please, give us an example of how this should work for RadChart? Can you use some example Dictionary and let us know how many series should be generated and what items they should have.  Maybe it is possible but we need to know what you are trying to do.

Thanks!

Kind regards,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
jfkrueger
Top achievements
Rank 1
answered on 24 May 2011, 08:07 PM
Hi,

I am trying to bind a chart to a List(Of Dictionary(String, String)) and am not having any luck. When you say "I ended up looping through my List of objects and creating DataSeries with manually added DataPoints. ", can you provide an example of how I would go about doing this?

Thanks!
0
Evgenia
Telerik team
answered on 27 May 2011, 03:21 PM
Hi Joe,

Could you elaborate a bit more on your scenario so that we will be able to advise you more properly? Why do you need to populate the Chart with a List of Dictionary?
You can data bind your chart using manual series mappings. When the datasource is Dictionary of data - just bind the appropriate data point members to your KeyValuePair's "Value" and "Key" properties. Here is a sample where the Keys (string) are set to be SeriesItemsLabels and the Values(double) - YValues.
 
public MainPage()
      {
          InitializeComponent();
          Dictionary<string, double> data = new Dictionary<string, double>() { { "Apples", 45d }, { "Oranges", 38 }, { "Grapes", 22d } };
          RadChart1.ItemsSource = data;
      }

And the XAML:
<telerik:RadChart x:Name="RadChart1">
          <telerik:RadChart.SeriesMappings>
              <telerik:SeriesMapping>
                  <telerik:SeriesMapping.SeriesDefinition>
                      <telerik:BarSeriesDefinition/>
                  </telerik:SeriesMapping.SeriesDefinition>
                  <telerik:SeriesMapping.ItemMappings>
                      <telerik:ItemMapping DataPointMember="Label"
                                         FieldName="Key" />
                      <telerik:ItemMapping DataPointMember="YValue"
                                         FieldName="Value" />
                  </telerik:SeriesMapping.ItemMappings>
              </telerik:SeriesMapping>
          </telerik:RadChart.SeriesMappings>
      </telerik:RadChart>

Regards,
Evgenia
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
Jim
Top achievements
Rank 1
answered on 28 Jun 2011, 07:02 PM
I have a situation which I think falls in this same boat where I'm trying to bind to a model containing a collection of item series and each series has a set of data points that I want to display on the chart. Each series should appear as a separate line/label in the chart. For example consider the following model:
public class MainModel
{
public IEnumerable<GroupModel> Group Models {get; set;}
}
public class GroupModel
{
public string Title {get; set;}
public IEnumerable<Item> Items {get; set;}
}
public class Item
{
public DateTime Date {get; set;}
public double Value {get; set;}
}

I would like to be able to have the itemssource of the Series mapping bound to the Items collection of the group models. And have n-number of series bound to the Models dynamically rather than having to set the SeriesMapping.CollectionIndex manually each time. Something along the lines of the following:
<telerik:RadChart Name="DetailChart" ItemsSource="{Binding Models}" Grid.Row="1">
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping LegendLabel="{Binding Title}" ItemsSource="{Binding Items}" ChartAreaName="chartArea" >
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:LineSeriesDefinition ShowItemLabels="False" ShowPointMarks="False" />
            </telerik:SeriesMapping.SeriesDefinition>
            <telerik:SeriesMapping.ItemMappings>
                <telerik:ItemMapping FieldName="Date" DataPointMember="XValue" />
                <telerik:ItemMapping FieldName="Value" DataPointMember="YValue" />
            </telerik:SeriesMapping.ItemMappings>
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
</telerik:RadChart>

 Is this possible with the RadChart, or do I need to modify my data structures? Please feel free to point me to a sample binding to a list of lists which doesn't require setting up each series mapping manually.

0
Evgenia
Telerik team
answered on 03 Jul 2011, 03:54 PM
Hi Jim,

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.
The radchart support of nested collection requires your seriesmapping to have collection index and the data for this mapping to be available in the underlying collection on the specified index.
The sample project attached demonstrates this.
Since Q1 2011 RadChart SeriesMappings supports new type of binding - Multiple DataSources. With it you are able to configure ItemsSource per SeriesMapping. For more information - take a look at our help topic and online demo.

I hope this is helpful.

Best wishes, Evgenia
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
Evan
Top achievements
Rank 1
Answers by
Vladimir Milev
Telerik team
Evan
Top achievements
Rank 1
jfkrueger
Top achievements
Rank 1
Evgenia
Telerik team
Jim
Top achievements
Rank 1
Share this question
or