The data cursor feature of the chart control allows the developer to synchronize the values of const lines with the mouse coordinates converted to axis coordinates. This feature works with both GDI+ and OpenGL devices and does not depend on the applied projection. Moreover, the feature triggers an event containing the mouse coordinates transformed to axis values.
You enable the data cursor feature by adding an object of type DataCursorTool to the InteractivityOperationsCollection of the control, accessible via the InteractivityOperations property:
VB.NET |
|
Dim dataCursorTool As DataCursorTool = New DataCursorTool() chartControl1.InteractivityOperations.Add(dataCursorTool)
|
C# |
|
DataCursorTool dataCursorTool = new DataCursorTool(); chartControl1.InteractivityOperations.Add(dataCursorTool);
|
Now let's take a close look at the properties of the Data cursor tool.
Controlling the data cursor axes
By default, the data cursor tool operates on the PrimaryX and PrimaryY axes. You can modify this behavior by modifying the HorizontalAxisId and VerticalAxisId properties of the DataCursorTool object. The following code for example will configure the data zoom cursor to operate on the Depth and PrimaryY axes:
VB.NET |
|
Dim dataCursorTool As DataCursorTool = New DataCursorTool() dataCursorTool.HorizontalAxisId = CType(StandardAxis.Depth, Integer) dataCursorTool.VerticalAxisId = CType(StandardAxis.PrimaryY, Integer) chartControl.InteractivityOperations.Clear() chartControl.InteractivityOperations.Add(dataCursorTool)
|
C# |
|
DataCursorTool dataCursorTool = new DataCursorTool(); dataCursorTool.HorizontalAxisId = (int)StandardAxis.Depth; dataCursorTool.VerticalAxisId = (int)StandardAxis.PrimaryY; chartControl.InteractivityOperations.Clear(); chartControl.InteractivityOperations.Add(dataCursorTool);
|
You can select an arbitrary pair of axes that are not collinear.
Synchronizing axis const lines with the mouse
The DataCursorTool can synchronize the values of two const lines: one for the selected horizontal axis and one for the selected vertical axis with the current mouse coordinates converted to coordinates in the coordinate system defined by the horizontal and vertical axes. The following code creates two const lines and instructs the data cursor to synchronize the const lines' values with the mouse when a left mouse click occurs:
VB.NET |
|
Dim chart As Chart = chartControl1.Charts(0) Dim constLine As AxisConstLine = New AxisConstLine() constLine.FillEffect.SetSolidColor(Color.FromArgb(255, 0, 0)) chart.Axis(StandardAxis.PrimaryX).ConstLines.Add(constLine) constLine = New AxisConstLine() constLine.FillEffect.SetSolidColor(Color.FromArgb(0, 255, 0)) chart.Axis(StandardAxis.PrimaryY).ConstLines.Add(constLine) Dim dataCursorTool As DataCursorTool = New DataCursorTool() dataCursorTool.HorizontalAxisId = CType(StandardAxis.Depth, Integer) dataCursorTool.VerticalAxisId = CType(StandardAxis.PrimaryY, Integer) dataCursorTool.HorizontalAxisConstLineIndex = 0 dataCursorTool.VerticalAxisConstLineIndex = 0 dataCursorTool.DataCursorMode = DataCursorMode.MouseDown chartControl.InteractivityOperations.Clear() chartControl.InteractivityOperations.Add(dataCursorTool)
|
C# |
|
Chart chart = chartControl1.Charts[0]; AxisConstLine constLine = new AxisConstLine(); constLine.FillEffect.SetSolidColor(Color.FromArgb(255, 0, 0)); chart.Axis(StandardAxis.PrimaryX).ConstLines.Add(constLine); constLine = new AxisConstLine(); constLine.FillEffect.SetSolidColor(Color.FromArgb(0, 255, 0)); chart.Axis(StandardAxis.PrimaryY).ConstLines.Add(constLine); DataCursorTool dataCursorTool = new DataCursorTool(); dataCursorTool.HorizontalAxisId = (int)StandardAxis.Depth; dataCursorTool.VerticalAxisId = (int)StandardAxis.PrimaryY; dataCursorTool.HorizontalAxisConstLineIndex = 0; dataCursorTool.VerticalAxisConstLineIndex = 0; dataCursorTool.DataCursorMode = DataCursorMode.MouseDown; chartControl.InteractivityOperations.Clear(); chartControl.InteractivityOperations.Add(dataCursorTool);
|
The DataCursorMode property controls when synchronization will occur. The following table describes the possible values for this property:
DataCursorMode |
Description |
MouseDown |
Synchronization will occur when the user presses the left or right mouse keys. |
MouseMove |
Synchronization will occur on each mouse move event. It is not recommended to set the data cursor tool in this mode for complex charts as it will slow down the control (it will repaint on each mouse move event). |
MouseDrag |
Synchronization will occur when the user drags the mouse over the control window. |
Finally, the DataCursorTool can trigger an event that contains information about the mouse coordinates transformed to axis coordinates, each time synchronization occurs. The following code intercepts this event:
VB.NET |
|
… Dim dataCursorTool As DataCursorTool = New DataCursorTool() AddHandler dataCursorTool.DataCursorChange, AddressOf OnDataCursorChange chartControl.InteractivityOperations.Add(dataCursorTool) … Private Sub OnDataCursorChange(ByVal sender As Object, ByVal eventargs As EventArgs) Dim dcea As DataCusorToolEventArgs = CType(eventargs, DataCusorToolEventArgs) Dim fHorizontalAxisValue As single = dcea.HorizontalAxisValue Dim fVerticalAxisValue As single = dcea.VerticalAxisValue End Sub
|
C# |
|
… DataCursorTool dataCursorTool = new DataCursorTool(); dataCursorTool.DataCursorChange += new EventHandler(OnDataCursorChange); chartControl.InteractivityOperations.Add(dataCursorTool); … private void OnDataCursorChange(object sender, EventArgs eventargs) { DataCusorToolEventArgs dcea = (DataCusorToolEventArgs)eventargs; float fHorizontalAxisValue = dcea.HorizontalAxisValue; float fVerticalAxisValue = dcea.VerticalAxisValue; }
|
See Also
DataCursorTool