I'm trying to figure out a way to determine which XAxis Label the mouse is currently hovering over. (If it matters, I am using ValueLabels for the actual XAxis labels being displayed).
What I'm trying to do is when the mouse is hovering over the XAxis Labels (like the 0, 1, 2, 3 etc. in the XAxis label area) I need to determine which label value the mouse is over so I can display a tooltip specifically related to that particular label value.
For example, if the mouse is over the 0, I want to display a value for a specific Year and Fiscal Calendar Week to the user like "2009 - 209"
And if the mouse hovered over the 1, it would display "2009 - 210" etc.
I've been able to determine that the mouse is over the XAxis region area, but I can't get what label it's specifically over. I've tried the:
.CoordToDataIndex(x,y,Points,s,p,d) and .CoordToPointIndex(x,y,Points,s,p,d)
but they only return me the nearest point data which doesn't help me if the chart has data that contains HOLE values since it seems to ignore the hole values and gives me the 'closest' point which could be several points away from where the mouse is actually hovering over.
I appreaciate any help I can get on this.
Mike...
Hi Mike,
I am attaching a sample that should be of assistance to you. I placed a breakpoint on the line where I give the label it tooltip text value. I hope this helps.
Regards,
-Raleigh
Raleigh,
Thanks for the quick reply. I can see what you have done, but so far I haven't been able to get it to work for my situation. In your example you are only displaying 1 label. That's OK, I figured what you were doing. But in my situation I was wanting to have the labels appear in the AxisX area like normal Tick mark labels. I tried playing with your code and switched it over to the AxisX labels. But I could not get the label itself to ever appear within the AxisX area on the tick marks. I tried adjusting the AttachMethodData.Y, AttachMethodData.X, and Offset values but with no luck. I did set the PointIndex to a particular point and that displayed the value label on that point within the graph, but that isn't what I was wanting.
Any other thoughts?
The only other thought I'm think of doing is adding an additional Grouping that will have it's series extend the full length of the chart with Zero values for each point. I may then be able to use the normal Dataindex method using that grouping and simulate the tooltip when hovering over it.
I just tried what I was thinking of doing with a second group, but that didn't work. It's giving me another item in the legend which I don't want the users to see so I really can't use that.
So basically what I think I need is just to know how to crete the labels like you did in your example program but I want them to actually appear within the AxisX area on the correct tick (Major) marks.
I apologize that my previous sample did not help you much. I'm attaching a modified version of my previous sample for you to look at. This example uses multiple labels and places them on the X-Axis. Please let me know if this helps or not.
Thanks Raleigh,
That looks exactly like what I need. I'll see if that works for us. I see where I may have gone wrong in my attempt. I changed the .AttachMethod to .DataIndexX thinking I needed to apply it to that mode. Very interesting.
Thanks again,
Raleigh
One more question that I hope will be as easy as the first one.
I've attached a screen shot of my issue. When using valuelabels, it appears that the auto spacing of the labels no longer works. Looking at my screen shot the bottom image shows the chart if I remove my valuelabels. The numbers autoadjust (not sure of correct terminology for this) so the number goes from 0,5,10,15 etc.
But when I use the Valuelabels they do not so the numbers start overlapping each other.
Is there some easy way to prevent this from happening?
My thought is that if in the Chart.Resize() event if I could figure out the distance between 2 point values on the chart I might be able to determine that if that distance is too small then I would recreate the Valuelables skipping a certain number between points to prevent them from overlapping. But I haven't been able to find a conversion procedure to get me some values to work with correctly.
Any suggestions on this. I promise, this is my last issue to complete on my project.
Thanks,
Hello Mike,
Are you using the loop as I did? If you are, you could remove the "i++;" from the last line, and replace it with "i+=5;" or "i = i+5;". This will attach a ValueLabel every five points, instead of every point. If this is not acceptable for your application, please let me know and I will see what I can do. I hope this helps.
I haven't changed over to your exact code yet, but mine is similar in the looping (and I noticed in your example, it was doing the same thing if the form was made narrow enough). But, I need every Point label to show when the chart is large enough to do so and then skip overy other lablel (or more) if the chart has been shunk down in size. (I'm making this project as a user control that will be placed on another form so it's size could vary based on the parent forms size). So I was hoping there was some indicator that would either tell me when I should be skipping labels or at least be able to determine distance between major ticks marks (or points) so I can make my own determination of when I should skip labels.
Please see the attached sample for a possible solution. This sample is a modified version of my previous sample (basically broken down into separate functions) that recreates the Value Labels when the form is re-sized and uses a random number of data points. The number of value labels added to the X-Axis is based on the width of the form. Please let me know if this helps.
I'm going to look at your example but I don't think it will do what I need. Since we load the data from a database, at different times we might have 10 points on the graph and other times we might have 60 points (or more) etc. So just based on the graph size will not work since the lower number of points displayd are wider apart than a higher number of points displayed. This is why I was thinking of some way more trying to figure out an x-pixel separation between two different points to try to determine how close they are together.
But, I'm going to check your example just in case you did do something like that in it.
I did check your example. And it only did what I expected. When your test project form is initially loaded you have AxisX labels of 0 to 10. If you start dragging it narrower slowly, the AxisX tick marks change to where it's only showing tick marks at 0, 2.5, 5, 7.5, and 10. Not really sure what values these tick marks are representing but they don't match the labels at that point. So this is where I could see one problem. But then my original problem would still exist in that using varying data points, I could not just simply use the charts width to determine when it should skip labels.
Does this work if you are using both the y-axis and the y2-axis? How about if your only using the y2 axis?
Would it be possible to add a tooltip property to the ValueLabel class so this work around wasn't needed?
Could tooltip functionality be added so the even if you are using AnnotationMethodEnum.Value you could have tooltips? This might solve mharo's second problem.
Later
Walleye