The two methods that convert pixel coordinate values into chart data coordinates and data indices are the CoordToDataCoord and CoordToDataIndex methods of the ChartGroup object. Both of these methods take a coordinate value, presumably from a MouseMove event, and return a PlotArea coordinate or the nearest data point.
The CoordToDataCoord method takes four parameters. The first two parameters (e.X and e.Y in the example below) are the pixel coordinates from the MouseMove event. The second two parameters are integer values that the method will fill with the X and Y Data Coordinate data. The following code is an example of this method in the MouseMove event:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim CoordXOutput As Double Dim CoordYOutput As Double C1Chart1.ChartGroups.Group0.CoordToDataCoord(e.X, e.Y, CoordXOutput, CoordYOutput) Debug.WriteLine("X Data Coordinate: " & CoordXOutput.ToString()) Debug.WriteLine("Y Data Coordinate: " & CoordYOutput.ToString()) |
To write code in C#
C# |
Copy Code
|
---|---|
double CoordXOutput = 0; double CoordYOutput = 0; c1Chart1.ChartGroups.Group0.CoordToDataCoord(e.X, e.Y, CoordXOutput, CoordYOutput); c1Chart1.ChartGroups.Group0. CoordToDataCoord(e.X, e.Y, ref CoordXOutput, ref CoordYOutput); ConsoleDebug.Writeline("X Data Coordinate: " + CoordXOutput.ToString()); ConsoleDebug.Writeline("Y Data Coordinate: " + CoordYOutput.ToString()); |
The CoordToDataIndex method takes six parameters. The first two parameters (e.X and e.Y in the example below) are the pixel coordinates from the MouseMove Event. The third parameter is a CoordinateFocusEnum value. This is an enumeration that specifies which axis to focus on when determining which data point is closer and its distance from the pixel coordinate. For instance, if X is selected as the focus, then it will return the nearest point that has the closest X-coordinate, regardless of the value of the Y-coordinate. The fourth and fifth parameters are integer values that the method will fill with the appropriate Series and Point indices. The sixth parameter is an integer value that the method fills with the distance from the pixel coordinate specified to the data point in pixels. The following code is an example of this method in the MouseMove event:
To write code in Visual Basic
Visual Basic |
Copy Code
|
---|---|
Dim SeriesOutput As Integer Dim PointOutput As Integer Dim DistanceOutput As Integer C1Chart1.ChartGroups.Group0._ CoordToDataIndex(e.X, e.Y, CoordinateFocusEnum.XandYCoord,_ ref SeriesOutput, ref PointOutput, ref DistanceOutput) Debug.WriteLine("Series Index: " & SeriesOutput.ToString()) Debug.WriteLine("Point Index: " & PointOutput.ToString()) Debug.WriteLine("Distance From Point: " & DistanceOutput.ToString()) |
To write code in C#
C# |
Copy Code
|
---|---|
int SeriesOutput = 0; int PointOutput = 0; int DistanceOutput = 0; c1Chart1.ChartGroups.Group0.CoordToDataIndex(e.X, e.Y, CoordinateFocusEnum.XandYCoord, ref SeriesOutput, ref PointOutput, ref DistanceOutput); ConsoleDebug.Writeline("Series Index: " + SeriesOutput.ToString()); ConsoleDebug.Writeline("Point Index: " + PointOutput.ToString()); ConsoleDebug.Writeline("Distance From Point: " + DistanceOutput.ToString()); |