We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Get axis in ChartRegionClick event handler

I am trying to create an event handler for ChartRegionClick (or ChartRegionDoubleClick) that will display the axis properties to the user (e.g. in a PropertyGrid) when the user clicks on the axis. 

I was hoping that e.Region (ChartRegionMouseEventArgs.Region) would give me what I want, but it does not seem to work. The e.Region.AxisIndex property is only set if the mouse is exactly over the axis line (e.g. if the mouse is on the axis labels, then e.Region.AxisIndex = -1). It is too difficult for the user to get the mouse directly on the axis line each time. If the user clicks on the axis labels, then e.Region.Type is set correctly (aka Region.Type = Axis), but I need to be able to find which axis was clicked.

Any suggestions on getting the exact axis when the user clicks on (or near) that axis?

1 Reply

DD Dharanidharan Dharmasivam Syncfusion Team August 18, 2016 10:22 AM UTC

Hi Mathew, 
Thanks for contacting Syncfusion support. We have analyzed your query and find the response for your query below. 

Currently we provide axis index value in Axes region and not in AxesLabel region, so you can’t able to get axis index value when you clicked in axis label region. We have created improvement task and for better follow up, we have created branch incident under your account

Since we don’t provide axis index values  in AxesLabel region, we have created work around sample in which we have compared the axis line bounds with the  mouse position X and Y  values obtained in the ChartRegionClick event. Find the code snippet below, 

Code Snippet: 
void chart_ChartRegionClick(object sender, ChartRegionMouseEventArgs e) 
           var axis = this.chart.Axes; 
           int x =e.Point.X; 
           int y = e.Point.Y; 
          for (int i = 0; i < axis.Count; i++) 
                if (x >= axis[i].Rect.X && x <= axis[i].Rect.X + axis[i].Rect.Width && y >= axis[i].Rect.Y && y <= axis[i].Rect.Y + axis[i].Rect.Height) 
                    MessageBox.Show("Axis Index: " + i);  


In the  screenshot we have highlighted the place where we have clicked in red color. 

For your reference we have attached the sample, kindly find the sample from the below link, 

Live Chat Icon For mobile
Up arrow icon