Get which area the mouse is over on a multiple area chart?

Hi, I've made an extension of the ChartCrossHairBehavior to display the Y axis value of the mouse cursor in a regular textblock when moving the cursor over the chart. In the SetPosition method of the ChartCrossHairBehavior I have this line 

PriceValue = ChartArea.PointToValue(PriceAxis, point) ;PriceAxis is the secondary axis

which gets the Y axis value of the current mouse position. This works fine. The problem is when the chart contains multiple areas in different rows, each having its own Y axis. When moving the cursor from a "sub-chartarea" to another, the value is still in relation to the main secondary axis of the chart. What I need is a way to know which area the mouse is over so that I can get the value in relation to the correct Y axis.

I've tried

ChartArea.InputHitTest(point)

but this doesn't give the chartarea or y axis.

Thank you.

3 Replies

SR Samuel Rajadurai Edwin Rajamanickam Syncfusion Team July 17, 2018 02:10 PM UTC

Hi Tom, 
  
Thank you for using Syncfusion products. 
  
We have analyzed your requirement and prepared the solution. The axis of a particular chart area can be get by overriding the GenerateLabels method and by fetching corresponding axis from the pointInfo property of the cross hair. 
  
The pointInfo property holds the information of the series, axis, point and label of a current point of the cross hair. 
  
Code Snippet 
  
                         
    public class CrossHairBehaviorExt : ChartCrossHairBehavior 
    {     
 
        protected override void GenerateLabel(ChartPointInfo pointInfo, ChartAxis axis) 
        {             
            base.GenerateLabel(pointInfo, axis); 
             
            // The corresponding axis can be get by checking the X and Y values. The X and Y values can also be get directly. 
            if(pointInfo.ValueY == null) 
            { 
                string x = pointInfo.ValueX; 
                var currentPrimaryAxis = pointInfo.Axis; 
            } 
            else 
            { 
                string y = pointInfo.ValueY; 
                var currentSecondaryAxis = pointInfo.Axis; 
            }           
        } 
    } 
 
  
We have also prepared a sample based on this. Please find it from the link below. 
  
  
Regards,
Samuel 



TO Tom July 17, 2018 04:41 PM UTC

This is exactly what I need, thank you Samuel.


MK Muneesh Kumar G Syncfusion Team July 18, 2018 04:23 AM UTC

Hi Tom, 

Thanks for the update.

We are glad to know that the given solution works. Please let us know if you need any further assistance.

Thanks,
Muneesh Kumar G.

Loader.
Up arrow icon