Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using Telerik's RadCartessianChart but I assume the problem (and hopefully solution) is the same for any charting controls.

I have a class looking something like

C#
public class GenericData
{
     ObservableCollection<double> XValues { get; set; }
     ObservableCollection<double> YValues { get; set; }

     public GenericData()
     {
          XValues = new ObservableCollection<double>();
          YValues = new ObservableCollection<double>();
     }
}


This is how the data is provided to me so it would be great if I could just set the data context of the chart to the instance of the object of type GenericData and set the XValueBinding="XValues" and YValueBinding="YValues" but it doesn't work like that I am finding out.

Is there any way I can achieve this goal?

Otherwise the only solution I can come up with is creating a wrapper object that structures the data into a Collection of GenericDatum which contains a single XValue and YValue. I really do not want to do this because speed is an issue in this application and iterating through the GenericData to create a new Collection is going to impact the performance.
Posted
Updated 29-Jan-15 4:27am
v2
Comments
Kenneth Haugland 29-Jan-15 11:16am    
Not an expert, but I assume that its normal to have a KeyValuePair and specify what values should be used for x and y in the binding.
MrGlass3 29-Jan-15 11:45am    
Normally I believe most people bind to a collection of objects which contain a single X and Y value. I am trying to do the opposite - bind to a single object that contains two collections, one of Xvalues and one of Yvalues.
Kenneth Haugland 29-Jan-15 11:51am    
http://docs.telerik.com/devtools/wpf/controls/radchartview/getting-started/introduction

People don't do that, or so it seems. They generally just create one collection with two properties, a key property and a value property, hence normally called a KeyValuePair, .NET even has an own function for it.

https://msdn.microsoft.com/en-us/library/5tbh8a42%28v=vs.110%29.aspx
MrGlass3 29-Jan-15 11:56am    
Yes. Sorry if I was unclear with how it is normally done vs how I am wanting to do it.

To put it another way, I would like to bind the Key (or XValues) to one collection of doubles and the value (or YValues) to a different collection of doubles. Is there any way to achieve that?
Kenneth Haugland 29-Jan-15 12:11pm    
Yes, but I dont really think there is a way around it. If speed is what you are worried about take a look at this:
http://blogs.msdn.com/b/timothyc/archive/2006/08/31/734308.aspx

Its mainly about 3D but it will apply to 2D as well.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900