Converting Pixel Coordinates into Data Points

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. The following code is an example of this method in the MouseMove event:

      Visual Basic

      C#

 Sample Project Available

For a complete sample using the CoordToDataCoord method, please see the StepChart or the CoordToMapping3D sample located http://helpcentral.componentone.com/Samples.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:

      Visual Basic

      C#

 Sample Project Available

For a complete sample using the CoordToDataIndex method, see DataStyl, PieStuff,StepChart, or Scatter samples located on http://helpcentral.componentone.com/Samples.aspx.


Send us comments about this topic.
Copyright © GrapeCity, inc. All rights reserved.