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?
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?