MousClick Events on Chart

  • Thread starter Thread starter Raymond Gilbers
  • Start date Start date
R

Raymond Gilbers

Guest
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.

Continue reading...
 
Back
Top