Mike O'Neal Posted June 11, 2007 Report Share Posted June 11, 2007 I am trying to set up a Gantt style chart where the point label from the data appears to the left of the chart. Some of the names are really long and I need to truncate them for display to prevent it from pushing the chart size down to nothing. I am trying to adjust the tooltip over the label on the x axis (now on the left in the Gannt chart) to show the full value by using the MouseMove event to determine I am over the axis area and the GetTip event to adjust the label to the full value. When I mouse over the label, the point is always returned as -1 instead of the correct point in both events. However, when I mouse over the datagrid column header for the same thing, both events return the correct point value. How do I determine which point it is so I can go get the correct value from my datasource? Link to comment Share on other sites More sharing options...
Frank Posted June 12, 2007 Report Share Posted June 12, 2007 For performance reasons, the HitTest is not done during a MouseMove, therefore Series and Point will always be -1 during this event. What you should do is simply store X and Y in the MouseMove event and then, during GetTip call HitTest with these values to determine the closest label. The following code snippet illustrates how to do this: private int m_lastMouseX,m_lastMouseY;private void chart1_MouseMove (object sender,HitTestEventArgs e) { m_lastMouseX = e.X; m_lastMouseY = e.Y;}private void chart1_GetTip (object sender,GetTipEventArgs e) { HitTestEventArgs a = chart1.HitTest(m_lastMouseX,m_lastMouseY); if ((a.HitType == HitType.Axis) && (a.Object == chart1.AxisX)) { int closestLabel = (int) Math.Round(a.Value); e.Text = "Long Label " + closestLabel.ToString(); } } Link to comment Share on other sites More sharing options...
Mike O'Neal Posted June 12, 2007 Author Report Share Posted June 12, 2007 Thanks!!! I was able to get what I needed with that. The piece of info I didn't understand was that the Value is returning a number that is the proportional distance up the x axis. Some additional info: Because I needed to determine which point I was on and refer back to the datasource to get the correct value, I used the following code in the GetTip() event to fix the tooltip only if I was on a point label in the axis. private void chart1_GetTip(object sender, GetTipEventArgs e){ if (e.Object == chart1.AxisX) { if (e.Text.Length > 0) { HitTestEventArgs e1 = chart1.HitTest(m_lastMouseX , m_lastMouseY); int currentPoint = (int)Math.Floor(e1.Value); if (currentPoint < ((DataView)chart1.DataSource).Count) { e.Text = (string)((DataView)chart1.DataSource)[currentPoint]["Long Field Name"]; } } } } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.