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

How to get event notification when clicking in axis label

Platform: WinForms |
Control: Chart |
Published Date: September 24, 2018 |
Last Revised Date: June 25, 2019

You can use ChartAxisLabelClick event to get index of the axis. This event will return axis index, label index and label text of the clicked label.

 

void chart_ChartAxisLabelClick(object sender, ChartRegionMouseEventArgs e)

{

    MessageBox.Show("Axis Index: " + e.Region.AxisIndex);

}

 

Other than ChartAxisLabelClick event, as an workaround you can ChartRegionClick event to get the axis index of the clicked label. Since the axis index value has been provided in Axes region, not in AxesLabel region, you cannot get axis index value when you click in axis label region. To get event notification when you click in axis label region, create a workaround sample, in which you can compare the axis line bounds with the mouse position X and Y values obtained in the ChartRegionClick event.

 

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

                }

            }

        }

 

The index of x-axis is displayed as 0, and the index of y-axis is displayed as 1. The following screenshot illustrates the result when clicking y-axis labels.

Chart with bar when clicking the y-axis in the chart

Sample link: axislabel-click

2X faster development

The ultimate WinForms UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon 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.Close Icon

Live Chat Icon For mobile