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

Multi series depeding on a property

3 Answers 67 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Pari
Top achievements
Rank 1
Pari asked on 07 Jun 2017, 09:38 AM

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

3 Answers, 1 is accepted

Sort by
0
Lance | Manager Technical Support
Telerik team
answered on 08 Jun 2017, 04:48 PM
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
0
Pari
Top achievements
Rank 1
answered on 10 Jun 2017, 02:47 PM

Hi Lance,

 

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

tnx again.

Cheers

 

 

0
Lance | Manager Technical Support
Telerik team
answered on 12 Jun 2017, 03:24 PM
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
Tags
Chart
Asked by
Pari
Top achievements
Rank 1
Answers by
Lance | Manager Technical Support
Telerik team
Pari
Top achievements
Rank 1
Share this question
or