# Converting Pixel Coordinates into Data Points

## Content



The two methods that convert pixel coordinate values into chart data coordinates and data indices are the [CoordToDataCoord](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroup.CoordToDataCoord.html) and [CoordToDataIndex](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroup.CoordToDataIndex.html) methods of the [ChartGroup](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroup.html) 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:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
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())
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
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());
```

DOC-DETAILS-TAG-CLOSE


> type=note
> **Note**: For a complete sample using the CoordToDataCoord method, please see the **StepChart** or the **CoordToMapping3D** sample located [here](https://developer.mescius.com/samples).

### CoordToDataIndex Method

The [CoordToDataIndex](/componentone/api/win/online-chart2d/dotnet-framework-api/C1.Win.C1Chart.4.8/C1.Win.C1Chart.ChartGroup.CoordToDataIndex.html) 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:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in Visual Basic

DOC-SUMMARY-TAG-CLOSE

```vbnet
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())
```

DOC-DETAILS-TAG-CLOSE

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
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());
```

DOC-DETAILS-TAG-CLOSE


> type=note
> **Note**: For a complete sample using the CoordToDataIndex method, see **DataStyl**, **PieStuff,** **StepChart**, or **Scatter** samples located [here](https://developer.mescius.com/samples).

## See Also

[Converting Data Points into Pixel Coordinates](/componentone/docs/win/online-chart2d/enduserinteraction/coordinateconversion/convertingpixelcoord/convertingdatapoints)