Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Zoom function does not work properly with waveform graph.

Hello,

 

I am using a waveform graph (in visual basic) to display data in real time. New data is added to the graph at a rate of 1 Hz using the "PlotYAppend" function. The graph is to display a total of 24 hours of data beginning at midnight, so I would have 00:00:00 as Xmin and 23:59:59 as Xmax. Everything works as expected except when I use the zoom functions.

 

I would like to for example zoom in on already plotted data (say 30 or 60 minutes worth) but when the next "PlotYAppend" is called (once a second) the zoom window changes to display newly appended data. Incidentally, the zoom window is of the correct size (Xmin/Xmax) just the wrong starting point.

 

For example, If it is currently 12:00:00 (noon) and I want to zoom in on the data from 09:00:00 to 10:00:00. What is displayed is a window from 12:00:00 to 13:00:00 with new data being added each second.

 

What do I need to do to zoom in on previously plotted data while new data is being appended?

 

Thanks in advance,

 

Chris 

 

0 Kudos
Message 1 of 7
(4,624 Views)

Hello Chris

 

One possibility would be for your code to recognize when you are zoomed in, and during this time, "plot" to an array instead of the graph.  Then, in the event when you zoom back out, you plot this array to the graph, and then resume plotting to the graph.  A very crude code snippet of this method can be seen below:

 

Public Class Form1

    Dim i As Double = 0
    Dim index As Integer = 0
    Dim zoomed As Boolean = False
    Dim dataBuf(1000) As Double



    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        If Not zoomed Then
            ZoomableGraph.PlotYAppend(Math.Sin(i * 0.25))
        Else
            dataBuf(index) = Math.Sin(i * 0.25)
            index += 1
        End If
        i += 1
    End Sub



    Private Sub ZoomableGraph_Zoom(ByVal sender As System.Object, ByVal e As NationalInstruments.UI.ActionEventArgs) Handles ZoomableGraph.Zoom
        zoomed = True
    End Sub



    Private Sub ZoomableGraph_ZoomPanUndone(ByVal sender As System.Object, ByVal e As NationalInstruments.UI.ActionEventArgs) Handles ZoomableGraph.ZoomPanUndone
        If zoomed Then
            Array.Resize(Of Double)(dataBuf, index)
            ZoomableGraph.PlotYAppend(dataBuf)
            zoomed = False
            Array.Resize(Of Double)(dataBuf, 1000)
            index = 0
        End If
    End Sub
End Class

 



Let me know if you have any questions, or if this may not fully meet your needs.

 

 

Thanks!

 

NickB

National Instruments 

Message Edited by nickb on 10-17-2008 02:34 PM
0 Kudos
Message 2 of 7
(4,606 Views)

Hello Nick,

 

Thanks for your comments. I think that this will work for us.

 

However I do have another question.

 

How do I prevent the "Pan" function from panning past the ends of the plot. As mentioned above, I am plotting 24 hrs worth of data at 1 sec intervals and I would like to limit the Pan function to 00:00:00 as the minimum and 23:59:59 as the maximum.

 

How can this be done?

 

Thanks

 

Chris

0 Kudos
Message 3 of 7
(4,554 Views)

Hey Chris,

 

In the axis range changed event, you could check if the max range has been exceeded, and if it has, you could programmatically pan back to the max range.  If you perform a very tight check (meaning the condition applies as soon as the max range is exceeded) there is no noticeable jumpy panning.  A code snippet similar to the following should help to achieve this:

 

 Private Sub WaveformGraph1_XAxisRangeChanged(ByVal sender As System.Object, ByVal e As NationalInstruments.UI.XAxisEventArgs) Handles WaveformGraph1.XAxisRangeChanged
        If WaveformGraph1.XAxes(0).Range.Maximum > myXAxisMax Then
            Dim panFactor As Single

            panFactor = 1 - ((myXAxisMax - WaveformGraph1.XAxes(0).Range.Minimum) / (WaveformGraph1.XAxes(0).Range.Maximum - WaveformGraph1.XAxes(0).Range.Minimum))
            WaveformGraph1.PanXY(-panFactor, 0)
        End If
    End Sub

 

 

NickB

National Instruments 

0 Kudos
Message 4 of 7
(4,539 Views)

Hello Nick,

 

Thanks for the suggestion, that works perfectly.

 

However, I am having trouble understanding the 'PanXY' function and implementing a similar fix for the Minimum Range. Could you provide an example of how to prevent panning below the minumin range as well.

 

When I Pan below the Minimum Range I get an 'Argument OutOfRange' exception.

I am using 0 as the Xaxis Minimum Range in Fixed Mode with DateTime as the Label Format. I don't think that the mode and label format have any thing to do with it.

 

Thanks again,

 

Chris

0 Kudos
Message 5 of 7
(4,514 Views)

Hey Chris,

 

The help for PanXY states the following:

 

An xFactor of 1.0 pans the plot area to the right so that the right edge of the plot area becomes the left edge of the plot area. An xFactor of -1.0 pans the plot area to the left so that the left edge of the plot area becomes the right edge of the plot area.

 

This means that PanXY takes a fractional factor that determines how far to move the screen.  A xFactor of .5 moves the graph screen from right to left half of the range of the xAxis, and vice versa for -.5.  Thus, for controlling the Max you can pan, you'll want to pass a negative factor, while you'll pass a positive factor for controlling the minimum.  

 

Modifying the code I posted earlier slightly, you can also ensure the user can never pan below 0:

 

If WaveformGraph1.XAxes(0).Range.Minimum < 0 Then
      Dim panFactor As Single

      panFactor = 1 - (WaveformGraph1.XAxes(0).Range.Maximum / (WaveformGraph1.XAxes(0).Range.Maximum - WaveformGraph1.XAxes(0).Range.Minimum))
      WaveformGraph1.PanXY(panFactor, 0)
      WaveformGraph1.XAxes(0).Range = New Range(0, WaveformGraph1.XAxes(0).Range.Maximum)
End If

 

I set the range at the end to ensure that the axis label reads 0, and not something like 3e-27, but depending on how your axis labels look this may not be necessary.  Please let me know if the PanXY function is still unclear to you, and I'll do what I can to clarify further.

 

NickB

National Instruments 

0 Kudos
Message 6 of 7
(4,508 Views)

I wanted to do something similar however I want to place the ruler in the picture you see, as the window pans left,

the ruler stays put. The user can scrool back for 1 hour, however 6 hrs would be great, (so I will use a circular buffer to strore data).  Issue is I don't know how to place the ruler in the window at the bottom( the waveforrm property does not have such a

graph. SEE attached picture

0 Kudos
Message 7 of 7
(3,284 Views)