Search code examples
c#wpfoxyplot

Complex (?) LineSeries itemsource object


I am trying to instantiate multiple line series using the same itemsource object by defining adifferent DataFieldY for each LineSeries Object.

I've got this working at first when i had and object with multiple properties like

class simple
{
   double time;
   double value1;
   double value2;
}

That way I could set the DataFieldY in one graph to DataFieldY="value1" for example. Now comes my problem, my class is slightly different since it comes from a Mongo database. I looks something like this:

class complex
{
   double timestamp;
   Backward b;
   Forward f;
}
class Backward 
{
   double backValue;
}
class Forward
{
   double forwardValue;
}

There are other variables of course and the hierarchy actually runs one level deeper. But this should work as an example.

What is the string that I need to add now at the DataFieldY considering that ItemSource is now equals to ObservableCollection<Complex>?

Also is there a way, maybe using reflection, for me to initialize all the line series using a foreach loop?

foreach(var s in Magic(complex))
{
    var ln = new LineSeries()
    ln.ItemSource = complexCollection
    ln.DataFieldT = s;
}

Maybe I am trying to do this in the wrong way too :)

Cheers


Solution

  • Turn b and f into public properties:

    class complex
    {
        ...
        public Backward b { get; set; }
        public Forward f { get; set; }
    }
    

    You should then be able to specify a nested property path, e.g.:

    DataFieldY = "b.backValue";