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.
CoordToDataCoord Method
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. Thefollowing code is an example of this method in the MouseMove event:
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())
· C#
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());
· Delphi
var
CoordYOutput: System.Double;
CoordXOutput: System.Double;
begin
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());
end;
For a complete sample using this method, please see the StepChart or the CoordToMapping3D sample located http://helpcentral.componentone.com/ProductResources.aspx.
CoordToDataIndex Method
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:
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())
· C#
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());
· Delphi
var
DistanceOutput: Integer;
PointOutput: Integer;
SeriesOutput: Integer;
begin
C1Chart1.ChartGroups.Group0.CoordToDataIndex(e.X, e.Y,
CoordinateFocusEnum.XandYCoord, SeriesOutput, PointOutput, DistanceOutput);
ConsoleDebug.Writeline(('Series Index: ' + SeriesOutput.ToString());
ConsoleDebug.Writeline(('Point Index: ' + PointOutput.ToString());
ConsoleDebug.Writeline(('Distance From Point: ' + DistanceOutput.ToString());
end;
For a complete sample using this method, see DataStyl, PieStuff, StepChart, or Scatter samples located on http://helpcentral.componentone.com/ProductResources.aspx.
Send comments about this topic to ComponentOne. Copyright © ComponentOne LLC. All rights reserved. |