12-08-2008 10:35 AM
I am plotting multiple channel data against time using a ScatterPlot. I would like for each different channel data read to have a unique line and point color. My legend does exactly what it's supposed to do, however, my graph plots all of the data in the same color. Also to add, in my ScatterPlot Collection Editor, I had to have one entry and it is named scatterPlot1.
My code is as follows:
ScatterPlot _data = new ScatterPlot();
ScatterPlot _data2 = new ScatterPlot();
//Add data plot to the graph collection
_graph3.Plots.Add(_data);
_graph3.Plots.Add(_data2);
if (_plot3.Data[0] != null)
{
//set data point style and color and line color
_data.PointColor = Color.Red;
_data.LineStyle = LineStyle.Solid;
_data.LineColor = Color. Blue;
legendItem1.Text = _plot3.Channels[0].DisplayName;
legendItem1.Source = _data;
}
_data.PlotXYAppend(xValue, yValue);
if (_plot3.Data[1] != null)
{
//set data2 point style and color and line color
_data2.PointColor = Color.Orange;
_data2.LineStyle = LineStyle.Solid;
_data2.LineColor = Color. OrangeRed;
legendItem2.Text = _plot3.Channels[1].DisplayName;
legendItem2.Source = _data2;
}
_data2.PlotXYAppend(xValue, yValue);
//end of code
Thanks in advance. Do you think I will have to draw it? If so, any examples?
12-09-2008 11:59 AM
Hi maramckmc,
I tried out your code, and it works fine for me, however, I commented out the two lines where you have "if (_plot3.Data[0] != null)" because I don't know what _plot3 is.
What is _plot3? Are you sure it is entering the code where it is setting the line colors?
We have some examples for changing the linestyles of a plot. The default installation directory is:
C:\Documents and Settings\All Users\Documents\National Instruments\MStudioVS2008\DotNET\Examples\UI\WindowsForms\Graph\CustomStyles\cs
I'm not sure how much that will help because you seem to be doing it correctly.
Another thing you could do is if you don't need to change the style of the plot at runtime you could just add them using the ScatterPlot Collection Editor and set up their properties there.
12-09-2008 12:27 PM
Thanks Kristen,
I did resort to going into ScatterPlot Collection Editor and added the plots to the graph. However, I am still encountering the same error. The color of my lines and points are still the latter. My legend is still correct. For instance, I have _data coming in at a constant value of 86 and _data2 coming in at a constant value of 50, both versus time. With my changing at runtime code, I was getting the points, but no line connecting the points, even though I had set the linestyle to solid. I wanted one line to only connect the "86" points and another only connecting the "50" points. Now, I do have a line and it is connecting 50 to 86 then back to 50, then back to 86.... I have no clue as to what's wrong. Again, my point and line color is of the latter. When I go and step thru my code, it shows that _data has its unique settings and _data2 had it;s. But it doesn't show on the graph.
_plot3 is my object from my database that gets the value of the channel.
12-10-2008 11:22 AM
Hi maramckmc,
The code you posted seemed to work for me.
Can you post your solution and code so I can run your project and see it not working?