Nevron Open Vision Documentation
Zooming and Scrolling

Cartesian charts support zooming and scrolling of the visible logical x and y axis ranges. The user can select a zoom in / out area from and then scroll using the axis scrollbars. In order to implement zooming and scrolling in a chart you need to create an interactor object that contains one or more tools related to zooming and scrolling.

Rectangle Zoom Tool

The NRectangleZoomTool allows the user to select an area of the chart used for zooming in or out. The following code snippet shows how to create an interactor that contains this tool:

C#
Copy Code

NInteractor interactor = new NInteractor();

NRectangleZoomTool rectangleZoomTool = new NRectangleZoomTool();

rectangleZoomTool.Enabled = true;

interactor.Add(rectangleZoomTool);

chart.Interactor = interactor;

This will enable rectangular data zooming with default parameters. Now when the user presses the left mouse button over the chart area and drags the mouse a semi transparent rectangle will appear that shows visually the area of the chart that will be displayed when the user releases the mouse button.

When the start position of the mouse in axis coordinates is smaller than the current position of the mouse in axis coordinates the chart will perform a zoom in of the axes. This means that when the user releases the left mouse button the axes will be configured to display only the area of the chart selected by the user.

In contrast when the start position of the mouse in axis coordinates is bigger than the current position of the mouse in axis coordinates the chart will perform a zoom out of the axes. When zooming out the selected area defines a range in the axis values where the current data visualized by the chart will be fit.

By default the chart will paint the selected area in semi transparent blue when a zoom in is about to occur and semi transparent red when a zoom out will occur.

Controlling the Zoom Axes

By default the zoom operates on the PrimaryX and PrimaryY axes. You can modify this by modifying the HorizontalAxis and VerticalAxis properties of the tool:

C#
Copy Code

rectangleZoomTool.HorizontalAxis = someXAxis;
rectangleZoomTool.VerticalAxis = someYAxis;

Controlling the Range of Selectable Values

The range of selectable values can be controlled through the HorizontalValueSnapper and VerticallValueSnapper properties of the tool.

The following code demonstrates how to prevent the user from selecting ranges that fall outside the axis ruler min/max values:

C#
Copy Code

rectangleZoomTool.HorizontalValueSnapper = new NAxisRulerClampSnapper();

rectangleZoomTool.VerticalValueSnapper = new NAxisRulerClampSnapper();

The Value Snapping topic discusses the different value snapper objects in more detail.

Range Selection Appearance

The ZoomInFill and ZoomInOut properties of the rectangle zoom tool allow you to modify the filling of the zoom area. The following code changes the default zoom in fill to semitransparent green:

C#
Copy Code

rectangleZoomTool.ZoomInFill = new NColorFill(NColor.FromColor(NColor.Green, 0.5f));

Data Pan Tool

The NDataPanTool allows you to scroll the chart contents using the mouse when the chart axes are configured to use paging (which is the case after a data zoom operation for example). The following code snippet shows how to create an interactor object that enables the user to zoom and pan the chart:

C#
Copy Code

NInteractor interactor = new NInteractor();

NRectangleZoomTool rectangleZoomTool = new NRectangleZoomTool();

rectangleZoomTool.Enabled = true;

NDataPanTool dataPanTool = new NDataPanTool();

dataPanTool.Enabled = true;

interactor.Add(rectangleZoomTool);

interactor.Add(dataPanTool);

chart.Interactor = interactor;

Now the user can zoom the chart and pan (by pressing and holding the right mouse key).

 

Send Feedback