Get Y value of series from the X Cursor position where a ChartArea is clicked on

后端 未结 3 2037
孤城傲影
孤城傲影 2020-12-22 08:42

I would like to get the Y Value for a series corresponding to the X position of a ChartArea that the user has clicked-upon.

I have tried to capture the X position o

3条回答
  •  滥情空心
    2020-12-22 09:19

    You'll need a MouseClick-Handler for your chart control instead of a normal Click-Handler, because of the "MouseEventArgs":

    private void chart1_MouseClick(object sender, MouseEventArgs e)
    {
        //check where you clicked, returns different information like the clicked series name and the index of the clicked point
        HitTestResult clicked = chart1.HitTest(e.X, e.Y);
        //this is how you get your y-Value
        double yValue = chart1.Series[clicked.Series.Name].Points[clicked.PointIndex].YValues[0];
    }
    

提交回复
热议问题