1

I am trying to plot multiple curves in different color on my graph. I am currently using one plotter (not sure if that will work, and that is why I am posting a thread here), and here is my code:

if (_dataXChA != null && _dataXChA.Length > 1)
{
  EnumerableDataSource<double> xChA = new EnumerableDataSource<double>(_dataXChA);
  xChA.SetXMapping(xVal => xVal);

  if (_dataYChA != null && _dataYChA.Length == _dataXChA.Length)
  {
    EnumerableDataSource<double> yChA = new EnumerableDataSource<double>(_dataYChA);
    yChA.SetYMapping(yVal => yVal);
    CompositeDataSource dsChA = new CompositeDataSource(xChA, yChA);
    ((LineGraph)plotter.Children.ElementAt(startIndex)).DataSource = dsChA;                   
    plotter.FitToView();
  }
}

if (_dataXChB != null && _dataXChB.Length > 1)
{
  EnumerableDataSource<double> xChB = new EnumerableDataSource<double>(_dataXChB);
  xChB.SetXMapping(xVal => xVal);

  if (_dataYChB != null && _dataYChB.Length == _dataXChB.Length)
  {
    EnumerableDataSource<double> yChB = new EnumerableDataSource<double>(_dataYChB);
    yChB.SetYMapping(yVal => yVal);                    
    CompositeDataSource dsChB = new CompositeDataSource(xChB, yChB);
    ((LineGraph)plotter.Children.ElementAt(startIndex)).DataSource = dsChB;
    //LineGraph lgChA = plotter.AddLineGraph(dsChB, _dataBrushColorChB, 1, "Data");
    plotter.FitToView();
  }
}

The first curve should be in green, and the second curve should be in red. plotter is CharterPlotter But when I look at the graph,I only got one curve. Then I looked at the data, it seems the curve displays the data from second data source, but the color of the curve is green.

The constructor assigns the color like this:

LineGraph lgChA = plotter.AddLineGraph(dsChA, _dataBrushColorChA, 1, "Data");
LineGraph lgChB = plotter.AddLineGraph(dsChB, _dataBrushColorChB, 1, "Data");

where,

_dataBrushColorChA = Colors.Green;
_dataBrushColorChB = Colors.Red;

Basically, I only update the data points each time when event occurs, because I have tried AddLineGraph(), but it turned out to be very slow, so I only update the data points. So, anyone give me any pointers? How can I handle this multiple data source situation?

Nick Tsui
  • 524
  • 2
  • 9
  • 29
  • I'm assuming this is the D3 library, is that correct? – WildCrustacean Jan 03 '13 at 15:37
  • I think it is. The plotter is a DynamicDataDisplay.CharterPlotter. – Nick Tsui Jan 03 '13 at 15:38
  • This is a guess, but it looks like you are setting the data source for the same plotter child at `startIndex` both times: `((LineGraph)plotter.Children.ElementAt(startIndex)).DataSource =`, maybe the index should be different for A and B? It might be drawing both curves right on top of each other if they are bound to the same data source. – WildCrustacean Jan 03 '13 at 15:44
  • Yup, I change the startIndex, making them from 2 points that are right next to each other, and they are now both displaying! Thanks a lot. Can you post your answer and I will accept it. :) – Nick Tsui Jan 03 '13 at 15:49
  • One more questions, I can change data source, but is there anyway I can change color of the brush as well? – Nick Tsui Jan 03 '13 at 15:53
  • So now you get two lines, but they are the same color? – WildCrustacean Jan 03 '13 at 15:54

1 Answers1

1

It looks like you are setting the data source for the same plotter child at startIndex for both channels:

((LineGraph)plotter.Children.ElementAt(startIndex)).DataSource = dsChA;

...

((LineGraph)plotter.Children.ElementAt(startIndex)).DataSource = dsChB;

The second assignment would cause the DataSource to be overridden by dsChB, which would make it only display one line.

Maybe the index should be different for A and B?

WildCrustacean
  • 5,896
  • 2
  • 31
  • 42