Home Forums WinForms controls Xceed Chart for WinForms getting the x-coordinate when double-clicked

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #18691 |

    Hi there,
    I want to take the x-y coordinates of the mouse with respect to chartControl when it is double-clicked on the chartControl. How can I do that does anyone knows?? right now I am using a dataCursor and a cursor moves when the cursor moves and when it is double-clicked the x-y coordinates of the cursor are the ones I want but it uses too much CPU and I need another way…

    Imported from legacy forums. Posted by Serkan (had 3589 views)

    User (Old forums)
    Member
    Post count: 23064

    You can use the HitTest() method on the ChartControl to accomplish this.

    e.g.

    //in form_load for example
    m_ChartControl.MouseDown += new System.Windows.Forms.MouseEventHandler(OnMouseDown);

    public void OnMouseDown(object sender, MouseEventArgs e)
    {
    HitTestResult hitTestResult = m_ChartControl.HitTest(e.X, e.Y);
    bool dataPoint = hitTestResult.DataPointIndex != -1;
    }

    You can open our Chart Explorer to have an example of what can be done ( Start Menu -> All Programs -> Xceed Components -> Our components in action! -> Xceed Chart Explorer for .NET ), then go to All Examples -> Interactivity -> Mouse Events.

    You can look at the code by clicking on the “C# Code” tab (you will find the complete source code of the explorer under -> C:\Program Files\Xceed Components\Xceed Chart for .NET and ASP.NET 4.0\Samples, and the VB.NET code too).

    Imported from legacy forums. Posted by André (had 241 views)

    User (Old forums)
    Member
    Post count: 23064

    Thanks for the reply but this is not what I want. I want the X value of the point with respect to data points not to the x-coordinate of the screen. For example assume we have a chart with 200 data points. The X-value of the graph on chart control must give me a number between 0 and 199.

    Imported from legacy forums. Posted by Serkan (had 300 views)

    User (Old forums)
    Member
    Post count: 23064

    This is what you need. Here is how you can do it (note that this example was done with a chart using multiple series) :

    <i>
    private void chartControl1_MouseDown(object sender, MouseEventArgs e)
    {
    //get the coordinates
    HitTestResult hit = chartControl1.HitTest( e.X, e.Y );
    System.Diagnostics.Debug.WriteLine( hit.SeriesIndex );

    //get the series
    BarSeries serie = ( BarSeries )hit.Series;
    System.Diagnostics.Debug.WriteLine( serie.Name.ToString() );

    //get the data point index
    int dataIndex = hit.DataPointIndex;

    //different things that can be done once you have the index :

    //value of the Y point
    System.Diagnostics.Debug.WriteLine( serie.Values[ dataIndex ].ToString() );

    //value of the X point (which a bar series does not have…)
    //System.Diagnostics.Debug.WriteLine( serie.XValues[ dataIndex ].ToString() );

    //label of the data point
    System.Diagnostics.Debug.WriteLine( serie.Labels[ dataIndex ].ToString() );

    //changing the FillEffect settings
    FillEffect effect = ( FillEffect )serie.Appearance.FillEffects[ dataIndex ];
    effect.Color = Color.HotPink;
    }
    </i>

    Imported from legacy forums. Posted by André (had 4380 views)

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.