Finding series item clicked in a chart in VB 2008

瘦欲@ 提交于 2019-12-24 09:27:50

问题


I am using VB 2008 with the Microsoft Chart Controls for .NET Framework. Using a pie chart, I would like to find the selected item when the chart is clicked or double clicked.

I am have the click and doubleclick events as shown here, which I have confirmed is being hit, and the the eventarts contains the x,y position of the click.

Private Sub Chart_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs)
Private Sub Chart_Click(ByVal sender As Object, ByVal e As System.EventArgs)

What I would really like to find out is what series item was clicked or doubleclicked (what pie slice).

This is being done in a windows forms application.

How do I get the series item clicked or doubleclicked?


回答1:


The following gives you the chart element under the Mouse.

Dim HTR as HitTestResult
Dim SelectDataPoint As DataPoint

HTR = Chart1.HitTest(e.x,e.y)
SelectDataPoint = Chart1.Series(0).Points(HTR.PointIndex)

Note that you should probably do some checking to make sure it is a Series that the user clicks on by checking the HTR.ChartElementType. Oh, and this should go in a MouseUp event, since the e that I use are MouseEventArgs.



来源:https://stackoverflow.com/questions/11316319/finding-series-item-clicked-in-a-chart-in-vb-2008

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!