MSChart 最近的数据点
我使用 Mschart 来制作图表。我想要获取的是我点击图表的位置最近的数据点。问题是我找不到 HitTest 值和数据点 x/y 值之间的任何联系。
假设我单击了以下点:
Dim result As HitTestResult = Chart.HitTest(e.X, e.Y)
现在我单击的位置有 X 和 Y 的值。 如何将其与数据点值关联起来?
我想要实现的是双击图表,它将找到最近的数据点(x,y 作为整数)并知道这些值,我将能够根据用户需要的位置重新计算其他值并双击。
有什么提示吗? P.
编辑:
到目前为止,它把我带到了这里:
Dim selectedDataPoint As DataPoint = Nothing
Dim hitResult As HitTestResult = Chart.HitTest(e.X, e.Y)
If hitResult.ChartElementType = ChartElementType.DataPoint Then
Me.Cursor = Cursors.Cross
selectedDataPoint = CType(hitResult.Object, DataPoint)
MsgBox(selectedDataPoint.Name)
MsgBox(selectedDataPoint.XValue.ToString)
MsgBox(selectedDataPoint.YValues(0).ToString)
End If
不幸的是,XValue 给了我“0”作为输出,实际上我有由“weeknumber/yearnumber”组成的字符串值。知道为什么会这样吗?
I use Mschart to produce charts. What I am trying to get is the nearest data point by where I click on the chart. The problem is that I can't find any connection between the HitTest values and the data point x/y values.
Say, I clicked on the following point:
Dim result As HitTestResult = Chart.HitTest(e.X, e.Y)
I have now values of X and Y where I clicked.
How to associate it with the data point values?
What I want to achieve is to double-click on the chart which would find the nearest data point (x,y as integer) and knowing these values I would be able to recalculate other values based upon where the user needs it and double-clicks.
Any hints?
P.
EDIT:
So far it brought me here:
Dim selectedDataPoint As DataPoint = Nothing
Dim hitResult As HitTestResult = Chart.HitTest(e.X, e.Y)
If hitResult.ChartElementType = ChartElementType.DataPoint Then
Me.Cursor = Cursors.Cross
selectedDataPoint = CType(hitResult.Object, DataPoint)
MsgBox(selectedDataPoint.Name)
MsgBox(selectedDataPoint.XValue.ToString)
MsgBox(selectedDataPoint.YValues(0).ToString)
End If
unfortunately the XValue gives me "0" as output where in fact I have string values composed with "weeknumber/yearnumber". Any idea why it is like this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,我找到了我的问题的答案。有兴趣的请看下面的代码:
Well I found an answer for my question. Please see the code below everyone who's interested: