locked
MousClick Events on Chart RRS feed

  • Question

  • Hello Forum Members,

    Im trying to get the x and y components when I click in a chart and place them in a Label.text. For some kind of reason I get only values when I click on the X axis or Y axis (so outside the chartarea.

    I have made a mousmove function that show continiously the X and Y values and that works now when I click on the graph the MouseClick event should store the values in a different label. Here are the two function I have.

    This is the MouseMove event

     private void chartCurrents_MouseMove(object sender, MouseEventArgs e)
            {
                //Cross Hair cursor for current measurements
                lbl_X_AxisCurrent.Location = new Point((e.X + 12), 30);
                lbl_Y_AxisCurrent.Location = new Point(60, (e.Y +26));
    
                if (e.X <= 85 || e.Y >= 170 || e.Y <= 20 || e.X >= 650)
                { 
                    lbl_X_AxisCurrent.Visible = false;
                    lbl_Y_AxisCurrent.Visible = false;
                    lbl_CurrentValues.Visible = false;
                }
                else
                {
                    lbl_X_AxisCurrent.Visible = true;
                    lbl_Y_AxisCurrent.Visible = true;
                    lbl_CurrentValues.Visible = true;             
                }
    
                try
                {
                    double yValue = chartCurrents.ChartAreas[0].AxisY2.PixelPositionToValue(e.Y);
                    double xValue = chartCurrents.ChartAreas[0].AxisX2.PixelPositionToValue(e.X);
    
                    lbl_CurrentValues.Text = string.Concat(string.Concat(Math.Round(xValue, 2).ToString(), ","), Math.Round(yValue, 2).ToString());
                    lbl_CurrentValues.Location = new Point(640, e.Y + 20);
                    lbl_CurrentValues.ForeColor = Color.DeepSkyBlue;
    
                }
                catch
                {
    
                }
                finally
                {
    
                }
            }


    Now I thought when I click on the graph the following event should start

    private void chartCurrents_MouseClick(object sender, MouseEventArgs e)
            {
                lblT1.Text = lbl_CurrentValues.Text;
    
            }

    But this function starts only ourside the graph area, why is that? And how can I solve this?

    I hope someone could help me thanks in advance.

    Monday, September 21, 2020 8:15 AM

Answers

  • I have found the my own answer. I use two labels and use them as cross hair identification. But those moving on top of the chart and their cross section was exactly below my cursor point. Therefore I never actually the event MouseClick activated. with a slight offset the issue has been solved.
    Monday, September 21, 2020 3:24 PM

All replies

  • I have found the my own answer. I use two labels and use them as cross hair identification. But those moving on top of the chart and their cross section was exactly below my cursor point. Therefore I never actually the event MouseClick activated. with a slight offset the issue has been solved.
    Monday, September 21, 2020 3:24 PM
  • Hi Raymond Gilbers,
    I am glad you have got your solution,we suggest that you mark it as the answer. So it can help other people who have the same problem find a solution quickly.
    Best Regards,
    Daniel Zhang


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, September 22, 2020 1:15 AM