In This Topic
Range selections are used to dynamically select ranges in the chart area. The range selection is defined by two intervals and two axes on which the intervals are scaled.
Creating a New Range Selection
You create an range selection by creating an instance of the NRangeSelection class and then adding it to the RangeSelections collection of the Chart:
C# |
Copy Code
|
NRangeSelection rangeSelection = new NRangeSelection();
someChart.RangeSelections.Add(rangeSelection);
|
Visual Basic |
Copy Code
|
Dim rangeSelection As New NRangeSelection()
someChart.RangeSelections.Add(rangeSelection)
|
Note that you can use the HorizontalAxisId and VerticalAxisId properties to define on which axes the range selection will scale.
Modifying the Range Selection Intervals
After you created the range selection you can modify its HorizontalAxisRange and VerticalAxisRange properties defining the range area:
C# |
Copy Code
|
rangeSelection.HorizontalAxisRange = new NRange1DD(10, 20);
rangeSelection.VerticalAxisRange = new NRange1DD(10, 20);
|
Visual Basic |
Copy Code
|
rangeSelection.HorizontalAxisRange = New NRange1DD(10, 20)
rangeSelection.VerticalAxisRange = New NRange1DD(10, 20)
|
Mouse Range Selection
In order to give the user to alibility to define a range selection with the mouse you must add the NDataZoomTool tool to the Controller.Tools collection of the control:
C# |
Copy Code
|
chartControl.Controller.Tools.Add(new NDataZoomTool());
|
Visual Basic |
Copy Code
|
chartControl.Controller.Tools.Add(New NDataZoomTool())
|
Now when the user presses the left mouse button the chart and drags the mouse the range selection will be synchronized with the area selected by the user.
Snapping
You may also want to snap the range selection to snap to certain positions of the axes it is displayed on. In this case you need to assign objects derived from the NAxisValueSnapper class to the HorizontalValueSnapper and/or VerticalValueSnapper properties of the range selection. For more information on axis value snapping please take a look at the Value Snapping topic.
Master / Slave Range Selections
When having multiple charts you may encounter situations where you want two or more range selections to be synchronized.
A typical example for this is a financial chart showing a stock value over time and a second chart showing the stock volume over time. You may wish to give the user the ability to select a range in the first chart and this should automatically reflect the range selection in the second and vice versa.
The Master / Slave range selection feature allows you to easily achieve this by specifying that the two range selections have a Master/Slave relationship.
Each range selection can have slave range selections that automatically synchronizes their ranges to the axis ranges of the master.
You can also have recursive master/slave relationship where two range selections are both masters and slaves to one another. In this case the range selection that initiates the synchronization takes priority.
The following code synchronizes the range selections of the stock value and stock volume charts:
C# |
Copy Code
|
NRangeSelection stockValueRangeSelection = new NRangeSelection();
NRangeSelection stockVolumeRangeSelection = new NRangeSelection();
stockValueRangeSelection.HorizontalValueSnapper = new NAxisMajorTickSnapper();
stockValueRangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
stockVolumeRangeSelection.HorizontalValueSnapper = new NAxisMajorTickSnapper();
stockVolumeRangeSelection.VerticalValueSnapper = new NAxisRulerMinMaxSnapper();
// each range selection is master of the other. When the users click on one of the
// charts this will result in an automatic update of the other range selection.
stockValueRangeSelection.Slaves.Add(stockVolumeRangeSelection);
stockVolumeRangeSelection.Slaves.Add(stockValueRangeSelection);
chartStockValues.RangeSelections.Add(stockValueRangeSelection);
chartStockVolumes.RangeSelections.Add(stockVolumeRangeSelection);
|
Visual Basic |
Copy Code
|
Dim stockValueRangeSelection As New NRangeSelection()
Dim stockVolumeRangeSelection As New NRangeSelection()
stockValueRangeSelection.HorizontalValueSnapper = New NAxisMajorTickSnapper
stockValueRangeSelection.VerticalValueSnapper = New NAxisRulerMinMaxSnapper
stockVolumeRangeSelection.HorizontalValueSnapper = New NAxisMajorTickSnapper
stockVolumeRangeSelection.VerticalValueSnapper = New NAxisRulerMinMaxSnapper
' each range selection is master of the other. When the users click on one of the
' charts this will result in an automatic update of the other range selection.
stockValueRangeSelection.Slaves.Add(stockVolumeRangeSelection)
stockVolumeRangeSelection.Slaves.Add(stockValueRangeSelection)
chartStockValues.RangeSelections.Add(stockValueRangeSelection)
chartStockVolumes.RangeSelections.Add(stockVolumeRangeSelection)
|
Events
When the range selection intervals change when they are modified from code or user drag operation it will raise the HorizontalAxisRangeChanged and VerticalAxisRangeChanged events.