ChartDirector 6.2 (.NET Edition)
Zooming and Scrolling Framework (Web)
The ChartDirector Zooming and Scrolling Framework is a framework for "logical zooming" of charts. "Logical zooming" means the chart is plotted with more details as it is zoomed in, but the chart objects do not necessary become bigger. The font size, line width, symbol size, etc, may remain the same. The chart may change type or use different data when it is zoomed in. For example, for a finance chart, it may start as a daily candlestick chart when the time range is long, and becomes a realtime intraday line chart when zoomed to one day.
The main elements of the ChartDirector Zooming and Scrolling Framework include a click and drag user interface to control zooming and scrolling, a set of methods to manage axis scales, and AJAX support to allow updating charts without refreshing the web page.
WebChartViewer/RazorChartViewer and JsChartViewer
The ChartDirector Zooming and Scrolling Framework for web applications is implemented in a server side control and a browser side control.
- WebChartViewer : This is the server side control for ASP.NET Web Forms. It handles AJAX communications with the JsChartViewer on the browser side.
- RazorChartViewer : This is the server side control for ASP.NET MVC. It handles AJAX communications with the JsChartViewer on the browser side.
For a typical web page with a zoomable and scrollable chart, the operation is as follows:
- The browser sends a request to the server for the web page.
- On the server side, the charting code creates the chart and assigns it to the WebChartViewer (for ASP.NET Web Forms) or RazorChartViewer (for ASP.NET MVC). The WebChartViewer or RazorChartViewer would then generated the HTML for the chart, with other necessary information to support zooming and scrolling and AJAX communications.
- The browser receives the web page from the server and displays the chart. The user can then use mouse or touch actions to zoom or scroll the chart.
- When a zooming or scrolling action occurs, the JsChartViewer will send an AJAX request to the server to update the chart.
- On the server side, a new chart is generated based on the updated axis scale, and the WebChartViewer or RazorChartViewer returns it to the browser as an AJAX response. The browser can then display the updated chart to the user.
The last three steps may repeat as the user continues to zoom or scroll the chart.
The above is only a brief description and omit many details. For example, custom parameters may be included in the AJAX request/response. Besides mouse or touch actions on the chart, the framework allows using external controls or custom methods for zooming and scrolling. In addition to updating the chart, the framework allows other custom things to be updated. These features will be discussed in the following sections.
The View Port
In the ChartDirector Zooming and Scrolling framework, the view port is used to determine which part of the data range should be plotted.
The view port can be imagined as a rectangular window over the entire XY data range. For example, suppose the full data range is 10 years in the horizontal direction. A view port width of 0.1 means only 10% of the horizontal data range should be plotted. In other words, the chart is zoomed in so that only 1 year of data is visible. The view port left side will determine exactly which year of data that is visible.
The view port position and size can be get and set on both the server side and the client side using the following properties and methods . The full data range is always assumed to be 0 to 1. So the view port position and size should be between 0 to 1.
Server Side Properties
Browser Side Methods
The Zoom and Scroll User Interface
control allows using mouse actions on the chart to control zooming and scrolling. Several mouse usage modes are supported, including drag to scroll, drag to select a region to zoom into, click to zoom in, and click to zoom out. They can be selected using JsChartViewer.setMouseUsage
. The zooming and scrolling direction can be horizontal only, vertical only, or both, configurable using JsChartViewer.setZoomDirection
When the user performs zooming or scrolling, JsChartViewer
will update the view port to reflect the new visible region and fires the JsChartViewer.ViewPortChanged
event . In typical usage, JsChartViewer.attachHandler
can be used to attach JsChartViewer.partialUpdate
as the ViewPortChanged event handler. This will cause an AJAX request to be sent to the server to update the chart when the view port changes.
WebViewPortControl/RazorViewPortControl and JsViewPortControl
In addition to using mouse or touch actions directly on the chart being zoomed or scrolled, ChartDirector provides the WebViewPortControl
(for ASP.NET Web Forms), RazorViewPortControl
(for ASP.NET MVC) and JsViewPortControl
to let users visualize and manipulate the view port managed by the JsChartViewer
In typical usage, the WebViewPortControl or RazorViewPortControl displays an "overall chart" that shows the full data range. On the browser side, the JsViewPortControl connects with the JsChartViewer using JsViewPortControl.setViewer
. The JsViewPortControl can then include a rectangle on the overall chart to represent the view port. The user can drag the rectangle to move the view port, which corresponds to scrolling. The user can also drag the rectangle border to resize the view port, which corresponds to zooming. In additional, the user can drag a new rectangular region as the new view port or click on a point on the overall chart to center the view port at that point. These user interactions can be configured with the methods of the WebViewPortControl, RazorViewPortControl or JsViewPortControl.
Zoom and Scroll with External Controls
In some applications, it may be desirable to have other ways to control zooming and scrolling. For example, in finance charts, there are often links that allow the user to jump to certain predefined period (eg. the last 30, 90, 180 or 360 days), which are essentially a type of zooming and scrolling.
To perform zooming and scrolling using external controls, the controls can update the view port position and size, and then fire the JsChartViewer.ViewPortChanged
event by using JsChartViewer.raiseViewPortChangedEvent
In some cases, the updates may need to be bi-directional - that is, the external controls may need to be updated when the view port changes. For example, suppose a scrollbar control is used to scroll the chart. When the user drags on the scrollbar, it can update the view port. The user may also drag on the chart directly to scroll the chart. In this case, the scrollbar would need to be updated to reflect that the changed view port.
To handle updating external controls when the view port changes, one may use the JsChartViewer.PostUpdate
event. This event occurs after the server has responded to the AJAX request from the browser, at which stage the view port should have been confirmed and validated by the server. External controls can be updated in the PostUpdate event handler to reflect the view port positions.
Custom Parameters in AJAX Requests and Responses
Apart from the view port state, in some cases, other custom parameters may be required to determine how to update the chart. For example, in a finance chart application, the server may need to know the "ticker symbol" to determine which data series to draw, and the "ticker symbol" can be controlled by the user through an HTML text box on the web page. In this case, during AJAX chart update, the contents of the HTML text box would also need to be sent to the server.
Similarly, in some cases, apart from updating the chart, the server may want to update other things in the web page. In this case, custom parameters would need to be sent from the server to the browser.
In ChartDirector, WebChartViewer.SetCustomAttr
can be used to transfer custom parameters between the server and the browser during an AJAX chart update.
In typical usage, to transfer parameters from the browser to the server, one may use JsChartViewer.setCustomAttr
in a JsChartViewer.PreUpdate
event. The PreUpdate event occurs just before an AJAX chart update, so any parameters set will be transferred immediately to the server. On the server side, WebChartViewer.GetCustomAttr
can be used to retrieve the parameters. If the server needs to transfer custom parameters to the browser side, it can use WebChartViewer.SetCustomAttr
. The browser can retrieve the parameters using JsChartViewer.getCustomAttr
in a JsChartViewer.PostUpdate
event, which occurs immediately after the browser receives an AJAX response from the server.
Managing Axis Scale
The view port always assumes the full data range to be 0 to 1. In practice, a chart can have multiple x-axes and y-axes, using a combination of date/time, linear and logarithmic scales.
To facilitate conversion between the view port and the axis scale, ChartDirector includes a number of methods as follows:
In typical usage, WebChartViewer.setFullRange
is used to define the full data ranges for the axes in the chart. WebChartViewer.getValueAtViewPort
can then be used to map between data values and view port positions. WebChartViewer.syncLinearAxisWithViewPort
can be used to synchronize the axis scale with the view port position.
is called without first defining the full data range, ChartDirector will automatically configure the axis scale based on the data in the chart, and assume it to be the full data range. This is useful if the full data range is not known but must be inferred from the data.
Server Side Code Structure
The server side code needs to handle both the initial page request and subsequent AJAX chart updates. The first thing it needs to do is to distinguish which type of requests it is handling, so that it can execute the appropriate code. WebChartViewer.IsPartialUpdateRequest
can be used to detect if the current HTTP request is an AJAX chart update request.
Initial Page Request
The initial page request is just a normal page request, and can be handled just like a normal web page request.
AJAX Chart Updates
In an AJAX chart update, only the chart needs to be updated. The server must return an AJAX response using WebChartViewer.PartialUpdateChart
instead of a normal web page.
Note that HTTP GET or POST parameters in the initial page request would no longer exists in subsequent AJAX chart updates. If these parameters are necessary in AJAX chart updates, they should be saved as custom attributes using WebChartViewer.SetCustomAttr
during initial page request. As custom attributes are persistent across AJAX chart updates, they can be retrieved using WebChartViewer.GetCustomAttr
and used in charting code.
Browser Side Code Structure
On the browser side, the typical code structure is:
Library Files Required for Zoomable/Scrollable Charts
A zoomable/scrollable chart requires the following files. Please ensure you copy the necessary files to the proper directories (typically the same directory as the script) and reference them using the proper paths.
|The script file for JsChartViewer and the supporting cursor and image files. They must be in the same directory.
Zooming and Scrolling Examples
© 2017 Advanced Software Engineering Limited. All rights reserved.