MSChart 最近的数据点

发布于 2024-12-12 04:32:39 字数 892 浏览 0 评论 0原文

我使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

澉约 2024-12-19 04:32:39

好吧,我找到了我的问题的答案。有兴趣的请看下面的代码:

If hitResult.ChartElementType = ChartElementType.DataPoint Then
            Me.Cursor = Cursors.Cross
            selectedDataPoint = CType(hitResult.Object, DataPoint)
            lblY.Text = selectedDataPoint.YValues(0).ToString
            lblX.Text = selectedDataPoint.AxisLabel.ToString
End if

Well I found an answer for my question. Please see the code below everyone who's interested:

If hitResult.ChartElementType = ChartElementType.DataPoint Then
            Me.Cursor = Cursors.Cross
            selectedDataPoint = CType(hitResult.Object, DataPoint)
            lblY.Text = selectedDataPoint.YValues(0).ToString
            lblX.Text = selectedDataPoint.AxisLabel.ToString
End if
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文