Winforms provides a HitTestInfo class which can be acquired by passing an x/y click coordinate to Chart.HitTest(int x,in y). This point is related to the chart image where 0,0 is the top left corner of the chart image. The HitTestInfo class contains information regarding the clicked position including the object that was clicked and how it relates to the data.
To get started, a click (or other event) handler must be set up. This code snippet demonstrates detecting a click on an element and displays a message box with the clicked element's name.
[C#] this.chart1.Click += new System.EventHandler(this.ClickOnChart);
private void ClickOnChart(Object myObject,EventArgs myEventArgs)
HitTestInfo hit = this.chart1.HitTest();
if(hit.Object is Element)
Element el = (Element)hit.Object;
[Visual Basic] Me.chart1.Click += New System.EventHandler(Me.ClickOnChart)
Private Sub ClickOnChart(myObject As [Object], myEventArgs As EventArgs)
Dim hit As HitTestInfo = Me.chart1.HitTest()
If TypeOf hit.Object Is Element Then
Dim el As Element = CType(hit.Object, Element)
MessageBox.Show(("Element=" & el.Name))
End Sub 'ClickOnChart
HitTestInfo & DataSource
The HitTestInfo class also provides a dataSource object which contains more detailed information about the clicked object. See the DataSource Tutorial for more information. The resulting DataSource object will also provide information regarding the context in which the clicked object is appears. For example the DataSource.SplitBy property could be set to ElementGroup meaning the clicked object represents a group of elements sharing a name or x value. This can result by clicking on the x axis tick which represents the shared element name. The DataSource class can be used to evaluate tokens and expressions by specifying a text string which behaves like a label. The method is string DataSource.EvaluateExpression(string).
Automatic interactivity features
Setting an elements tooltip or url does not require setting up an event handler, this functionality will automatically be provided.