ItemMapping for Dictionary

8 posts, 0 answers
  1. Evan
    Evan avatar
    9 posts
    Member since:
    Jul 2009

    Posted 14 Oct 2009 Link to this post

    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?
  2. Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 20 Oct 2009 Link to this post

    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.
  3. Evan
    Evan avatar
    9 posts
    Member since:
    Jul 2009

    Posted 22 Oct 2009 Link to this post

    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?
  4. Vladimir Milev
    Admin
    Vladimir Milev avatar
    1061 posts

    Posted 28 Oct 2009 Link to this post

    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.
  5. jfkrueger
    jfkrueger avatar
    269 posts
    Member since:
    Jul 2012

    Posted 24 May 2011 Link to this post

    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!
  6. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 27 May 2011 Link to this post

    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
  7. Jim
    Jim avatar
    4 posts
    Member since:
    May 2011

    Posted 28 Jun 2011 Link to this post

    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.

  8. Evgenia
    Admin
    Evgenia avatar
    1437 posts

    Posted 03 Jul 2011 Link to this post

    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
Back to Top