2D Chart for WinForms | ComponentOne
End-User Interaction / Coordinate Conversion Methods / Converting Pixel Coordinates into Data Points and Vice Versa / Converting Data Points into Pixel Coordinates
In This Topic
    Converting Data Points into Pixel Coordinates
    In This Topic

    The two methods that convert either data coordinates or data indices into pixel coordinates are the DataIndexToCoord and DataCoordToCoord methods of the ChartGroup object. The DataIndexToCoord method takes a series and point index and returns the client coordinates of the specified data point. The DataCoordToCoord method takes a set of data coordinates and returns a pixel coordinate. These methods are quite similar to the other conversion methods.

    DataIndexToCoord Method

    The DataIndexToCoord method takes four parameters, and returns a pixel coordinate as seen in the following example:

    To write code in Visual Basic

    Visual Basic
    Copy Code
               
    Dim CoordX, CoordY As Integer     
    C1Chart1.ChartGroups.Group0.
      DataIndexToCoord(ChartSeries, ChartPoint, CoordX, CoordY)    
    Debug.WriteLine("X Chart Coordinate: " & CoordX.ToString())    
    Debug.WriteLine("Y Chart Coordinate: " & CoordY.ToString())
    

    To write code in C#

    C#
    Copy Code
              
    int CoordX=0, CoordY=0;    
    c1Chart1.ChartGroups.Group0.
       DataIndexToCoord(ChartSeries, ChartPoint, ref CoordX, ref CoordY);  
    Debug.Writeline("X Chart Coordinate: " + CoordX.ToString());   
    Debug.Writeline("Y Chart Coordinate: " + CoordY.ToString());
    

    DataCoordToCoord Method

    The DataCoordToCoord method takes four parameters, and returns a pixel coordinate as seen in the following example:

    To write code in Visual Basic

    Visual Basic
    Copy Code
               
    Dim CoordX, CoordY As Integer       
    C1Chart1.ChartGroups.Group0._   
       DataCoordToCoord(DataCordX, DataCoordY, CoordX, CoordY)    
    Debug.WriteLine("X Chart Coordinate: " & CoordX.ToString())   
    Debug.WriteLine("Y Chart Coordinate: " & CoordY.ToString())
    

    To write code in C#

    C#
    Copy Code
              
    int CoordX=0, CoordY=0;      
    c1Chart1.ChartGroups.Group0.  
       DataCoordToCoord(DataCordX, DataCoordY, ref CoordX, ref CoordY);    
    ConsoleDebug.Writeline("X Chart Coordinate: " + CoordX.ToString());    
    ConsoleDebug.Writeline("Y Chart Coordinate: " + CoordY.ToString());
    

    Note: For a complete sample using the DataCoordToCoord method, see the PropGrid or the explorer samples located here.

    See Also