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.
Unfortunately, activation email could not send to your email. Please try again.

Get axis in ChartRegionClick event handler

Thread ID:

Created:

Updated:

Platform:

Replies:

125429 Aug 16,2016 07:02 PM Aug 18,2016 06:22 AM Windows Forms 1
loading
Tags: Chart
Mathew Weaver
Asked On August 16, 2016 07:02 PM

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?

Dharanidharan Dharmasivam [Syncfusion]
Replied On August 18, 2016 06:22 AM

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);  
                } 
            } 
        }  


Screenshot: 
 

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, 
Thanks, 
Dharani. 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;