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));
|