ChartDirector 6.1 (Java Edition)
Programmable Track Cursor (Web)
event handler so that the track cursor follows the mouse cursor. It is also possible to draw the track cursor at other times. For example, one may program the track cursor so that it is movable by arrow keys. In a realtime chart, the track cursor can be programmed to sweep through the chart as new data points are added.
can be used on the server side to generate a data structure containing the chart configuration. The data structure can then be passed to the WebChartViewer using WebChartViewer.setChartModel
Track Cursor Events
By far the most common usage of track cursor is when the mouse is moving over the plot area of an XYChart
. On touch enabled devices, the touch point can also be used. To implement these behaviour, the code can handle suitable mouse and touch events and draw the track cursor. The most common used events are:
A special feature of these plot area events is that it occurs even if the mouse or touch interaction is slightly outside the plot area, in which case JsChartViewer.getPlotAreaMouseX
will report as if the interaction is still on the edge of the plot area. This feature allows the user to easily position the track cursor on the edge of the plot area, at which the latest data points are often located. The margin around the plot area that would still trigger plot area events is configurable using JsChartViewer.setPlotAreaMouseMargin
In addition to the mouse or touch point moving over the chart, it is also possible for the chart to move under the mouse or touch point. For example, in a smart phone, the user can view the web page in portrait or landscape mode, and the web page can be designed to layout differently in these two modes. In this case, the chart can move or resize when the phone is rotated, and the track cursor would need to update. The JsChartViewer.ChartMove
event can be used to detect chart movement or resizing and update the track cursor.
can be used to attach a function as the handler to these events. This should be performed only after the chart is loaded. It is recommended that the code to attach the event handler be executed in the <body> or window onload event handler of the web page.
JsChartViewer Drawing Methods
To facilitate drawing track cursors, JsChartViewer
includes a number of methods to draw lines, rectangles and text over the chart as follows.
Snapping to the Nearest X Data Position
Very often, the track cursor is not drawn exactly at the interaction position, but is drawn at the data point position nearest to the interaction position in the x direction. ChartDirector includes a method JsXYChart.getNearestXValue
, which will search all data in the chart to get the x data value nearest to a given point. This value can then be used to obtain the x pixel coordinate (using JsXYChart.getXCoor
) for drawing the track cursor. It can also be used to look up the data points (using JsLayer.getXIndexOf
) so as to draw dots that track the data points, generate dynamic data labels, axis labels or legend entries.
, your web site would need to contain the following files, which should be in the same directory. In your web page, please include a <script> tag to load "cdjcv.js".
|wait.gif||Rotating clock wait symbol. |
|spacer.gif||A 1-pixel transparent image. |
|zoomin.cur||Zoom in cursor. |
|zoomin.cur||Zoom out cursor. |
Sample Track Cursors
ChartDirector includes a number of sample drawing routines in its sample code. You may reuse them, or modify them for your own needs. You may also develop your own track cursor drawing code to implement the track cursor behaviour you want.
|Track Line with Legend (Web)||Demonstrates a track cursor that consists of a vertical line snapped to the nearest x data position. There are dots to highlight the nearest data points, and a dynamically updated legend showing their values.
|Track Line with Data Labels (Web)||Demonstrates a track cursor that consists of a vertical line snapped to the nearest x data position with a floating x-axis label. There are also dots to highlight the nearest data points, with labels beside them displaying their values.
|Track Line with Axis Labels (Web)||Demonstrates a track cursor that uses horizontal and vertical lines to connect the nearest data points to the x-axis and y-axis, with floating axis labels showing their values.
|Track Line with Vertical Legend (Web)||Demonstrates a track cursor that consists of a vertical line snapped to the nearest x data position. There are dots to highlight the nearest data points, and a dynamically updated vertical legend showing their values. The legend box is put on the left side of the plot area if the track cursor is on the right side and vice versa. This ensures the legend box would not block the region near the track cursor.
|Track Box with Floating Legend (Web)||Demonstrates a track cursor that consists of a rectangle enclosing the slot corresponding to the nearest x-axis label. A floating legend box that moves with the mouse cursor is used to display the data values in that slot.
|Crosshair with Axis Labels (Web)||Demonstrates a track cursor that consists of a vertical line and a horizontal line at the mouse cursor position, thereby forming a crosshair. Floating axis labels are used to display the cursor position.
|Finance Chart Track Line (Web)||This is similar to Track Line with Legend (Web), but is modified to apply to the FinanceChart object.
|Zooming and Scrolling with Track Line (Web)||Demonstrates how to apply track cursors to a Zoomable and Scrollable chart. The track cursor drawing code is the same as that in Track Line with Legend (Web).
|Zooming and Scrolling with Viewport Control (Web)||Demonstrates how to apply track cursors to a Zoomable and Scrollable chart. The track cursor drawing code is the similar to that in Track Line with Legend (Web).
|Realtime Chart with Track Line (Web)||Demonstrates how to apply track cursors to a Realtime chart. The track cursor drawing code is the same as that in Track Line with Legend (Web).
© 2017 Advanced Software Engineering Limited. All rights reserved.