The data zoom tool allows the user to select a range to zoom in / out on the client by pressing the mouse over the chart and then dragging the mouse.
Creating a Data Zoom Tool
The following code snippet adds a data zoom tool to the Tools collection of the control:
C# |
Copy Code
|
---|---|
NThinChartControl1.Controller.Tools.Add(new NDataZoomTool()); |
Visual Basic |
Copy Code
|
---|---|
NThinChartControl1.Controller.Tools.Add(new NDataZoomTool()) |
Setting The Zooming Axes
The data zoom tool by default allows zooming in / out on the PrimaryX and PrimaryY axes of the currently selected chart. To modify this you need to change the XAxisId or YAxisId properties. The following code snippet tells the data zoom to use the Secondary Y axis for zooming:
C# |
Copy Code
|
---|---|
NDataZoomTool dataZoomTool = new NDataZoomTool(); |
Visual Basic |
Copy Code
|
---|---|
Dim dataZoomTool As New NDataZoomTool() |
Allowing X or Y Zooming
In some cases you need to restrict the zoom to only the X or Y axis. This is a common requirement when you have multiple series that scale on a common axis or when you have date time / data on the x axis for example. In this case you should set the AllowXAxisZoom and AllowYAxisZoom properties of the tool according to your preferences. The following code snippet shows how to disable Y axis zooming:
C# |
Copy Code
|
---|---|
NDataZoomTool dataZoomTool = new NDataZoomTool(); |
Visual Basic |
Copy Code
|
---|---|
Dim dataZoomTool As New NDataZoomTool() |
Data Zoom Sample
The following code snippet shows how to create a simple XY scatter chart with data zooming and scrolling. The example intercepts the ScrollCallback and DataZoomCallback in order to update the label with the current X / Y ranges:
C# |
Copy Code
|
---|---|
public partial class _Default : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (!NThinChartControl1.Initialized) NThinChartControl1.Panels.Clear(); // add a label // get the default chart // create a XY scatter point // add some random data label.Text = FormatLabel(NThinChartControl1, chart.Axis(StandardAxis.PrimaryX), chart.Axis(StandardAxis.PrimaryY)); // set the active chart // add data zoom tool private static string FormatLabel(NThinChartControl control, NAxis horzAxis, NAxis vertAxis) } [Serializable] #region INScrollbarCallback Members public void OnScroll(NThinChartControl control, NCartesianChart chart, NAxis axis) #endregion } [Serializable] #region INDataZoomCallback Members public void OnDataZoom(NThinChartControl control, NCartesianChart chart, NAxis horzAxis, NAxis vertAxis) #endregion } } |