Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Zoom In/Out while graphing in ScatterGraph

Hi,
 
I am trying to use the zoom in/out features in C#.NET.  The graph is a scattergraph. It seems both zoom in and zoom out working well after the data are plotted. However, I can only zoom in while the data are being added to the plot. Zoom out is not working at all in the case.
 
I wonder if you support this feature in the current version 8.0.1. If yes, how do I fix this problem. If not, do you plan to support this feature and how soon?
 
Thanks,
NRCA-Sue
0 Kudos
Message 1 of 5
(5,225 Views)
Hi NRCA-Sue,

You are correct.  This is the behavior of the graph control because the zoom history is lost when you plot data.  Zooming out makes use of the previous zooms in, and the graph control doesn't know of previous zooms each time you plot data to it.  One way people have worked around this has been to keep track of the zoom ranges, and create event handlers for the zoom and unzoom event, so the history of zooms is kept there.

Gavin Fox
Systems Software
National Instruments
0 Kudos
Message 2 of 5
(5,196 Views)
Hi,

Thanks for the reply.  I was curious about what I would need to do in the zoom/unzoom event handlers.  If I keep track of the zoom history information, how do I apply it to the graph control in the event handlers?  For example, in the unzoom handler, what do I need to do to reset the axis information and clear the graph's zoom history?

Thanks,
NRCA-Sue
0 Kudos
Message 3 of 5
(5,177 Views)
Hi NRCA-Sue,

We've seen people successfully implement the zoom history as a stack.  So on the unzoom event, which is
the ZoomPanUndone event, you could pop off the top stack item, and go back in history to the last zoom.  In the zoom event, you would add to the stack. 
You should be able to get to the graph properties from the "sender" event argument.

Here are other threads that discuss this issue. 

Is the pan/zoom history reset with every PlotXY()?
http://forums.ni.com/ni/board/message?board.id=232&message.id=3109&requireLogin=False

WaveformGraph and maintaining zoom factors between waveform plots?
http://forums.ni.com/ni/board/message?board.id=232&message.id=4078&view=by_date_ascending&page=1

Gavin Fox
Systems Software
National Instruments
0 Kudos
Message 4 of 5
(5,162 Views)

Hope my code can help people to make zooming available without any modifiers keys (alt, shift or ctrl)

 

 

		private void scatterGraph1_PlotAreaMouseWheel(object sender, MouseEventArgs e)
		{
			if (Keyboard.Modifiers == 0) // No shift, alt or ctrl
			{
				double zoomFactor;
				if (e.Delta > 0)
				{
					zoomFactor = .8; // .008 = 1/1.25, same as NI
				}
				else
				{
					zoomFactor = 1.25;
				}

				RectangleF rect = new RectangleF();
				rect.X = (float)scatterGraph1.Plots[0].XAxis.Range.Minimum;
				rect.Width = (float)(scatterGraph1.Plots[0].XAxis.Range.Maximum - scatterGraph1.XAxes[0].Range.Minimum);

				rect.Y = (float)scatterGraph1.Plots[0].YAxis.Range.Minimum;
				rect.Height = (float)(scatterGraph1.Plots[0].YAxis.Range.Maximum - scatterGraph1.YAxes[0].Range.Minimum);

				double newWidth = rect.Width * zoomFactor;
				double newHeight = rect.Height * zoomFactor;

				scatterGraph1.ZoomAnimation = false;
				scatterGraph1.ZoomXY(scatterGraph1.Plots[0], rect.X + ((rect.Width - newWidth) / 2), rect.Y + ((rect.Height - newHeight) / 2), newWidth, newHeight);
			}
		}

 

 

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