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

后端 未结 3 2033
孤城傲影
孤城傲影 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:08

    First convert the mouse click position to a relative position:

    x= 100.0 * e.X / chart.Width
    

    Then convert relative position to axis position:

    double xMin= axis.Minimum;
    double xMax= axis.Maximum;
    double pMin= axis.GetPosition(xMin);
    double pMax= axis.GetPosition(xMax);
    xx= (x-pMin) * (xMax-xMin) / (pMax-pMin) + xMin;
    

    Then use the axis position to probe the series (eg interpolate or nearest point as you like)

提交回复
热议问题