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

Adding X values to StackedBarSeries Chart throws exception

1 Answer 20 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Kayode Leonard
Top achievements
Rank 1
Kayode Leonard asked on 05 May 2010, 10:43 PM
I am building upon the existing Telerik.Windows.Examples.Chart.Gallery.StackedBar example and want to specify the actual x values in the series.  In the example, the ItemSource is bound to a List<int[]>, instead of business objects.
I specify the X series like so:

SeriesMapping smX = new SeriesMapping();

smX.CollectionIndex = 0;
ItemMapping imX = new ItemMapping();
imX.DataPointMember = DataPointMember.XValue;
smX.ItemMappings.Add(imX);

The collection that gets bound to the ItemSource of the RadChart has at index 0, the x values for each index.
When I run this it gives an exception Invalid Property or field - 'Value' for type: int
I notice in the example, they use default x values and cleverly don't show you how to set them explicitly.
The only place they set XValues explicitly are in charts where the Items are bound to business object properties.
Can I specify X values while still using a List of arrays for the ItemSource values?

 

1 Answer, 1 is accepted

Sort by
0
Nikolay
Telerik team
answered on 10 May 2010, 11:57 AM
Hello Kayode Leonard,

Thank you for your interest in our controls.

You can specify XValue or XCategory implicitly by binding IEnumerable of objects.You need to define the FieldName of the ItemMapping before configuring and binding the Chart to the appropriate properties in the following manner :

<telerikCharting:SeriesMapping.ItemMappings>
<telerikCharting:ItemMapping DataPointMember="XValue" FieldName="FieldName1"></telerikCharting:ItemMapping>
<telerikCharting:ItemMapping DataPointMember="YValue" FieldName="FieldName2"></telerikCharting:ItemMapping>
</telerikCharting:SeriesMapping.ItemMappings>

I believe this help topic would be helpful to you and would give you more tips and information on the matter. Please note, that if the property, you're binding the X axis to, is numeric, you need to set the XValue of the DataPointMember property, whereas binding the X axis to string values requires setting XCategory. Unfortunately, this scenario is not supported when binding to list of arrays. You can create a custom class and send a generic list to RadChart.

If you need further assistance, please, do not hesitate to contact us. 

Sincerely yours,
Nikolay
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
Kayode Leonard
Top achievements
Rank 1
Answers by
Nikolay
Telerik team
Share this question
or