Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

How to extract data values from all plots in graph at a specified point in time

Hi,

I have an application where I use several plots in the same graph (and several graphs stacked under each other). The x axis is a timeline constructed from with DateTime array, the y axis holds data values.

 

The previous version of this application used cursor to indicate the Y data value at a specified point in time (just by hovering the mouse, and snapping to the nearest point).

 

For the new version, it is preferable to hover the mouse, but be able to extract the Y values from all plots at the same time in a text box, like this:

 

Y data 1 value: 0.2

Y data 2 value: 1,4

Y data 3 value: 2.8

Y data 4 value: 8.3

At time 12/12-2008  08:00

 

I have tried all kinds of methods to extract the data at a specified time position, but they do not work as expected. I need input on how to obtain these values. I need something like (pseudo)

 

foreach (Plot plot in Graph.Plots)

   double dataValueOfThisPlot = plot.GetDataAtTime(new DateTime(12, 12, 2008 ,. etc.....))

 

- Thanks a lot!

0 Kudos
Message 1 of 5
(4,507 Views)

Here's a small update on this,

as you can see from the attached image I have 2 plots aligned over each other. The vertical bars follow the mouse when we are in "cursor navigation mode". The labels "CYCLIC_TIME" and FPULSE1 now show up with value NaN, I need to be able to retrieve the correct data values at the point in time where the mouse is.

 

I find the exact point in time of where the mouse is, but getting from there to actually getting out the values from different plots in the graph at that time instant does not seem easy to do with the current API.

 

I saw some tips somewhere about storing your own data vectors on the outside for lookup, but that is not feasible in this case because of the extra memory consumption. Also, direct lookup from stored media is not smart, as the raw data is stored in a zipped format...

 

Any input on this, anyone??

0 Kudos
Message 2 of 5
(4,483 Views)

Hello -

 

I think the trick here is to let the cursor do the heavy lifting for you.  The general idea is as follows:

 

  1. Use Plot.InverseMapDataPoint to get the x location from the mouse location
  2. Loop through each plot, associating the cursor with each plot.
  3. Make sure the snap mode for the cursor is set to "ToPlot" for each plot
  4. Set the x position of the cursor to the position obtained earlier
  5. Get the y position of the cursor - this is the value of the plot at the corresponding x location
  6. Reset the cursor to it's original plot and original snap mode (this is only important if all the plots do not share the same x axis)

Here's the important part of the code I wrote to get the associated screenshot:

 

NickB_03-25_10-13-21.png

 

private void ShowPlotValues(PointF mouseLoc)
{
  string[] lines = new string[waveformGraph1.Plots.Count];
  double val, x = 0d, y;

  for (int i = 0; i < lines.Length; i++) {
    waveformGraph1.Plots[i].InverseMapDataPoint(waveformGraph1.Plots[i].GetBounds(), mouseLoc, out x, out y);
    DateTime time = NationalInstruments.DataConverter.Convert<DateTime>(x);
    waveformGraph1.Cursors[0].SnapMode = CursorSnapMode.ToPlot;
    waveformGraph1.Cursors[0].Plot = waveformGraph1.Plots[i];
    waveformGraph1.Cursors[0].XPosition = x;
    val = waveformGraph1.Cursors[0].YPosition;
    lines[i] = string.Format("Plot {0}: {1} {2}", i + 1, time.ToString("H:mm:ss"), val);
  }
  waveformGraph1.Cursors[0].SnapMode = CursorSnapMode.Floating;
  waveformGraph1.Cursors[0].XPosition = x;
  textBox1.Lines = lines;
}

 

NickB

National Instruments

0 Kudos
Message 3 of 5
(4,472 Views)

Hi,

Thanks a lot, that works very well!

 

Is it also possible to obtain the exact time of the sample points (so I know which time stamp to assign each point)? I would think its available, since it snaps to the nearest data point, but cant quite see how to set up the cursor to retrieve this. The way your works now, the time used as input remains unchanged..

0 Kudos
Message 4 of 5
(4,462 Views)

Hello -

 

Once you've set the XPosition property, you can then query the XPosition property again to see the value after the cursor has snapped to the nearest point on the associated plot.  This will be a double value though, so it will need to be converted to a DateTime value.  Maybe the easiest way to do that is through the DataConverter.Convert method.

 

Is that what you were asking?

 

NickB

National Instruments

0 Kudos
Message 5 of 5
(4,457 Views)