Multi series depeding on a property

4 posts, 0 answers
  1. Pari
    Pari avatar
    6 posts
    Member since:
    Dec 2016

    Posted 07 Jun Link to this post

    Hi

    I have an ObservableCollection of a class object which has some properties such as: datetime, value, and category_id

    I would line to create a multi series chart depending on category_id

    eg:

    products with category_id=1 one lineseries. X axis :datetime, Y axis: value

    products with category_id=2 another lineseries in the same Chart. X axis :datetime, Y axis: value

    etc.

    Could you provide to me a solution for code behind and for MVVM? I think I have to use Data Triggers but I am facing some problems implementing them.

    tnx in advance

  2. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    347 posts

    Posted 08 Jun Link to this post

    Hi Pari,

    The Xamarin.Forms RadChart doesn't have a SeriesProvider property that you can bind to, however you can achieve the same result by doing the following:

    var vm = BindingContext as StartPageViewModel;
     
    // 1 - Group the original data in the ViewModel by the CategoryId of each item
    var uniqueCategorySeriesData = vm.OriginalData.GroupBy(i => i.CategoryId);
     
    // Add a series for each one of the groups
    foreach (var seriesData in uniqueCategorySeriesData)
    {
        chart.Series.Add(new LineSeries
        {
            ItemsSource = seriesData.ToList(),
            ValueBinding = new PropertyNameDataPointBinding("Value"),
            CategoryBinding = new PropertyNameDataPointBinding("Timestamp")
        });
    }


    I've attached a demo that does this using items that have an CategoryId of 1 and 2.

    Here's the result at runtime:




    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    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 Feedback Portal and vote to affect the priority of the items
  3. Pari
    Pari avatar
    6 posts
    Member since:
    Dec 2016

    Posted 10 Jun in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Hi Lance,

     

    tnx for your reply. I will try it. Are you planning to implement the Series.Provider in Xamarin.Forms?

    tnx again.

    Cheers

     

     

  4. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    347 posts

    Posted 12 Jun Link to this post

    Hello Pari,

    We do have the feature request on our backlog. You can upvote and follow it by going to the public Feedback Portal Item here.

    Regards,
    Lance | Tech Support Engineer, Sr.
    Progress Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top