How to get event notification when clicking in axis label
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.
Sample link: axislabel-click