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

DataSeries collection

6 Answers 121 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Mattias
Top achievements
Rank 1
Mattias asked on 31 Aug 2009, 12:31 PM
Hi,

I have a collection with DataSeries that I want to add to my chart. Each of these DataSeries have correct LegendLabel, XCategory and YValue the way I want it.

The problem is adding or binding them to the chart.
How do I bind this in xaml so that the chart understands what XCategory to use and what value it is supposed to be in there for each serie? As far as I can understand I have to transform my Collection<DataSeries> to a DataTable and also add a SeriesMapping. Problem is that the collection is changing all the time so it seeds to be bound and updated upon changes as well.

I also tried to use _chart.DefaultView.ChartArea.DataSeries.Add() but when I then do DataSeries.Clear() when my Collection changes I get an error saying "The calling thread cannot access this object because a different thread owns it."

6 Answers, 1 is accepted

Sort by
0
Velin
Telerik team
answered on 02 Sep 2009, 08:53 AM
Hi Mattias,

RadChart supports automatic rebinding when its items source has changed. All you need to do is to define the SeriesMapping objects which will represent the visual series of items in runtime. You can check our online examples for information on how to set up categorical chart. There is also a help article on this matter available here.

Best wishes,
Velin
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
Mattias
Top achievements
Rank 1
answered on 07 Sep 2009, 02:18 PM
Hi Velin,

I would love to use the MVVM example but the problem is that instead of having a Person as Category i have something closer to a full "Class", so Class0, Class1 and so on contains as a XCategory where Person0, Person1 are Series with values in all of there Classes. If that makes sense.

The question is how I do that?

So instead I have a Class that holds a Collection<DataSeries> where all the YValues, XCateogries, Brush and LegendLabel is already prepared. What I want to do now is to bind this Class and create a DataTemplate. But how do I set up a templats for this? Can I set a property on <chart:ChartDefaultView> that binds to my Collection<DataSeries>? I haven't found a way to do that so far.

The only solution right now is to create a RadChart object and bind that directly. But this seems to be both messy and problematic when it comes to show/hide Legend, Header and Pointvalues and I have to reload the whole chart.

Any suggestions on this?
0
Velin
Telerik team
answered on 10 Sep 2009, 09:18 AM
Hello Mattias,

The recommended way to set up an instance of the RadChart control is to set its ItemsSource property to a collection of custom data objects and fill its SeriesMappings collection with SeriesMapping instances. Each SeriesMapping object is used internally by the control to map the properties of your data objects to a DataSeries object containing the DataPoint instances need to visually represent the original data.  Each DataPoint object represents a data object from the original ItemsSource and its properties are initialized based on the ItemMapping objects contained in the ItemMappings collection property of each SeriesMapping defined. This is why you do not need to bind the control to a pre-created Collection<DataSeries> - you will have this created automatically when you provide the ItemsSource and set up the appropriate SeriesMappings and ItemMappings. 

If the property you want to use as category happens to be a custom object, you could either provide a meaningful override of its ToString() method or just introduce a new string property of the data object which to format the data.

You can show/hide the legend using this code:
RadChart1.DefaultView.ChartLegend.Visibility = Visibility.Collapsed; 

Hope this will help.

Sincerely yours,
Velin
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
Mattias
Top achievements
Rank 1
answered on 10 Sep 2009, 01:55 PM
Hi Velin,

Okay, that was what I was afraid for. To me it seems strange that I can't databind a Collection<DataSeries> if I have premade one. It already includes all the mapping I need so it should be fine the way it is. So what I have to do it so map it to a DataTable (or similar) and set up SeriesMappings?

I also tried to create a RadChart from my Model that I populated using DataSeries.Add, and send that out and bind it to the "content"-tag of the chart. That works fine, but by doing that I can't seem to get styling and templates working on the chart. It is like all the content, including styling and everything is set once I bind the content-tag. Is that true or can I set content to a "RadChart"-object and still use styling on the different chart-parts?
0
Velin
Telerik team
answered on 15 Sep 2009, 03:19 PM
Hi Mattias,

if you have a collection of DataSeries objects, you can simply add them to the DataSeries collection exposed by the chart area. Here is how you can do this:
RadChart1.DefaultView.ChartArea.DataSeries.AddRange(MyDataSeriesCollection); 

All the best,
Velin
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
AdaDog
Top achievements
Rank 1
answered on 05 Mar 2010, 08:46 PM
I agree with the assertion.  There are many cases where the number of series are not known, the series need to be bound to DataContext, and the characteristics of how each series is displayed is dependent the nature of the individual series (e.g. ItemMapping, SeriesDefinition, etc.). 

Writing code-behind is a step backward.  These properties/objects should be DependencyProperties/DependencyObjects.  If nothing else, this would enable consumers to develop attached properties.
Tags
Chart
Asked by
Mattias
Top achievements
Rank 1
Answers by
Velin
Telerik team
Mattias
Top achievements
Rank 1
AdaDog
Top achievements
Rank 1
Share this question
or