Is there any disadvantage of using a ScatterGraph over a WaveformGraph?
It depends on your data. If your data is linear and has a consistent increment between points, WaveformGraph is easier. If you have X/Y data pairs or you have non-linear data, ScatterGraph is easier.
As I create and add each plot, I need a scheme of not using the same color for any plot. I'm assuming that I would want to re-use colors when a plot was removed. What do you recommend for this situation?
There are several ways you could do this. One suggestion would be to create a list of colors that you want to use for your plots and take a color off the list and assign it to the LineColor property of the plot when it's added to the collection. For example, you could create a Queue of colors in your form like this:
private static readonly Queue plotColors = new Queue();
static MyForm()
{
plotColors.Enqueue(Color.Red);
plotColors.Enqueue(Color.LightBlue);
plotColors.Enqueue(Color.Yellow);
plotColors.Enqueue(Color.Orange);
plotColors.Enqueue(Color.Green);
// Add additional colors ...
}
Then you could add an event handler for the graph's PlotsChanged event and handle the assignment of the plot color like this:
private void OnPlotsChanged(object sender, CollectionChangeEventArgs e)
{
XYPlot plot = e.Element as XYPlot;
Debug.Assert(plot != null, "CollectionChangeEventArgs.Element is not an XYPlot.");
Debug.Assert(plotColors.Count > 0, "The queue of plots colors is empty.");
switch (e.Action)
{
case CollectionChangeAction.Add:
// Pick the next color in the queue for the added plot.
plot.LineColor = (Color)plotColors.Dequeue();
break;
case CollectionChangeAction.Remove:
// Put the removed plot color back into the queue.
plotColors.Enqueue(plot.LineColor);
break;
default:
break;
}
}
Now when you add plots to the graph's Plots collection, new differentiating colors should automatically be assigned to the plot, and when you remove plots from the graph's Plots collection, the color should be added back to the queue and can be recycled in a future plot. Hope this helps.
- Elton