12-03-2008 10:52 AM
Hello,
I am plotting 24 hours of data at an interval of 1 second (in real time) and I wish to have the plotting continue from the left side of the plot at the beginning of each day WITHOUT clearing the existing data from the previous day. I plan to use the cursor features to indicate the current time of day as it moves across the graph. I have tried to use the PLOTY and the PLOTYAPPEND methods but I am having trouble going from the right margin to the left margin at the beginning of each day.
I have also tried storing the data in an array and using PLOTWAVEFORM, but with 32 channels (PLOTS) and 86400 seconds/day (data points) it is too resource intensive.
Does anyone know how to implement this functionality?
Thanks
Chris
12-04-2008 02:26 PM
Hello Chris,
When you detect a new day, you should be able to explicitly specify the starting point of the x-axis range for the Waveform Graph. Waveformgraph1.XAxes.Item(0).Range will allow you to set this value. You will also need to prevent the Waveform Graph from autoscaling the x-axis when it updates data when employing this approach, otherwise it may simply negate this effort.
12-04-2008 03:00 PM - edited 12-04-2008 03:01 PM
Hello Chris,
Just to add to what Matt said, if you are trying to keep a constant 24 hour xAxis, and want to maintain the previous day's data while the current day's data plots, you could implement a sweep mode for the waveform graph, similar to what LabWindows/CVI and LabVIEW offer. Because Measurement Studio does not offer this functionality natively, you will have to add it yourself, but I have tried to simplify this for you with the following ideas and example program.
One possible way to implement this would be two have two plots for each channel of data you have. One plot would be responsible for the previous day's data, and the other would be responsible for plotting the current days data. This way, when one day completes, you switch your active plot to be the oldest plot, clear this oldest plot, and then commence plotting the current day's data. Once you have this implemented, all that is left to do (if you wish) is to make the previous day's data disappear as you plot the current day's data, resulting in a graph that looks similar to the following:

This feature is implemented by creating your own LineStyle class, inheriting from the National Instruments.UI.LineStyle class. You will then need to override the CreatePen method, as well as a few others. Below are the important snippets of code demonstrating this approach, with comments. Also, you will find the entire example attached below, so that you can examine it in it's entirety. Please let me know if this is not what you were looking for, or if you have any questions about any of the code.
The following is the code that swaps which plot is being used to actively plot data:
private void waveformGraph1_PlotDataChanged(object sender, XYPlotDataChangedEventArgs e)
{
xyCursor1.XPosition = counter;
if (counter >= 499) /* the end of the 'day' has been reached */
{
if (plotObject == waveformPlot1) /* switch plots */
{
disLineStyle.LineColor = plotObject.LineColor; /* switch the line color for the custom line style */
plotObject.LineStyle = disLineStyle; /* set the day old plot to the custom line style */
plotObject = waveformPlot2;
plotObject.LineStyle = LineStyle.Solid; /* reset the line style for the current plot */
xyCursor1.Plot = plotObject;
this.Text = "Using Waveform Plot 2...";
}
else
{
disLineStyle.LineColor = plotObject.LineColor;
plotObject.LineStyle = disLineStyle;
plotObject = waveformPlot1;
plotObject.LineStyle = LineStyle.Solid;
xyCursor1.Plot = plotObject;
this.Text = "Using Waveform Plot 1...";
}
counter = 0; /* reset your counter */
plotObject.ClearData(); /* clear the old data */
}
/* get the context coordinates of the currently plotted point, in order to know where to start erasing */
disLineStyle.TransitionPoint = plotObject.MapDataPoint(waveformGraph1.PlotAreaBounds, xyCursor1.XPosition, 0.0).X - waveformGraph1.PlotAreaBounds.X;
}
The following is the implementation of the custom line styles CreatePen method:
public override Pen CreatePen(object context, LineStyleDrawArgs args)
{
Rectangle bounds = args.ContextBounds;
/* Add 1 to width and height of context bounds to include */
/* the right and bottom edge of the rectangle in the linear */
/* gradient brush */
bounds.Width += 1;
bounds.Height += 1;
/* create a new linear brush to go from transparent to opaque */
using (LinearGradientBrush lBG = new LinearGradientBrush(bounds, Color.FromArgb(0, _lineColor), _lineColor, LinearGradientMode.Horizontal))
{
Blend blend = new Blend(); /* create a blend objet to make gradient instantaneous */
float transition = (float)_transitionPoint / (float)args.ContextBounds.Width;
float[] factors = {0.0f, 0.0f, 1.0f, 1.0f};
float[] positions = {0.0f, transition - .01f, transition, 1.0f}; /* make the gradient switch at the transition point */
blend.Factors = factors;
blend.Positions = positions;
lBG.Blend = blend;
return new Pen(lBG, args.Width);
}
}
For the rest of the implemenation, please see the attachment.
NickB
National Instruments
12-05-2008 08:07 AM
Thanks Nickb,
This is a great deal to absorb, but based on your descriptions it sounds like just what I need (It is unfortunate that Measurement Studio does not have this functionality).
I will need to take some time to digest all of this and also this is a lower prioity item for me right now.
So I thank you in advance for your assistance.
Chris
12-05-2008 10:36 AM
Hey Chris,
I just thought that I would mention that the Measurement Studio help has a very good help topic describing some of the things I've done that may assist you as you try to implement these ideas into your own application. The name of the help topic is:
Creating a Custom Line Style for the Measurement Studio Web Forms Graph .NET Controls
Please don't hesitate to let me know if you have questions as you examine these ideas.
NickB
National Instruments
12-07-2008 10:35 PM
Hi Nickb,
I managed to find some free time over the weekend to study your example and as it turns out this is exactly what I am looking for. However, I have developed my application using VB 2008 (I know, I should have mentioned this). I attempted to try and translate your example to VB but with no success.
Could you PLEASE provide the example in VB if it is not too much trouble.
Thanks
Chris
12-08-2008 12:50 PM
Hey Chris,
While my VB.NET is... well... rusty, hopefully the following can be of some use to you. Again, most of this was taken from the help topic I mentioned earlier, which should be helpful to you as you try to implement these features.
Once again, please let me know if I can help clarify anything about the project.
NickB
National Instruments
12-10-2008 01:39 PM
Hi Nick,
Thanks for taking the time to translate your example to VB for us.
I was able to incorporate the methods you provided in your example into our application and have it working mostly the way we want it to. As mentioned above, our application uses 33 channels of data to populate 33 plots each with a different color (unrelated plots will use the same colors). The user has the ability to select which plots to view. There are 4 plots visible by default each with a uniqe color and this is the configuration used to test the new code.
The application works as expected for the most part. The plots begin each day at the left margin and maintain the proper colors. However, the plots from yesterday have changed to all be the same color.
I have made alterations to your example (attached) to demonstrate what we are trying to do except with only 2 channels. The example will show the colors change at the end of the plot and the new plots assuming new colors. Our application will use the same color for each plot each day.
Could you please have a look at the example to see why it is doing this. What am I missing?
Thanks again,
Chris
12-10-2008 04:07 PM - edited 12-10-2008 04:07 PM
Hey Chris,
The reason the 'old' plots are changing to a single color is that they are all using the same DisappearingLineStyle object, disLineStyle. Thus, when you set the color of this custom line style:
disLineStyle.LineColor = Plot(Channel).LineColor
you are only ever updating one reference, and all of your 'old' plots are using that single reference. Just like you have to have multiple plots to have multiple colors, each plot will have to have it's own DisappearingLineStyle object in order have multiple colors when using the DisappearingLineStyle class. Your code may need to look something like this:
disLineStyle(Channel).LineColor = Plot(Channel).LineColor
Please let me know if I can be any more help.
NickB
National Instruments
12-10-2008 05:37 PM
Hey Chris,
One last thing before I head home for the night. As I was thinking about the need you are going to have for multiple instances of these custom LineStyle classes, it may be best to make the TransitionPoint property 'Shared', so that you don't have to individually update this property for each object, and because it should be the same value for each instance of the class. I didn't think about that being an issue when I wrote that example for you, as it was more intended to demonstrate concepts than to provide a robust class.
NickB
National Instruments