MS Chart控件Sleection Rectangle

时间:2016-05-15 19:13:43

标签: .net vb.net mschart

如果有人能帮我解决问题,我将非常感激。我在VB.Net Chart上绘制了一些数据,如下图所示。 Chart Example

我需要的是在图表上用鼠标选择一些点(我想出如何选择一个点,但诀窍是选择一组点......)并将它们放在某个数组中?

期待您的回答。

1 个答案:

答案 0 :(得分:0)

我会尽量更精确。这是我到目前为止所做的事情,并不多。我是编程的初学者,所以要温柔:)

 chGrupa1.ChartAreas(0).CursorX.IsUserSelectionEnabled = True
    chGrupa1.ChartAreas(0).CursorY.IsUserSelectionEnabled = True
    Dim htrResult As HitTestResult = chGrupa1.HitTest(Cursor.Position.X, Cursor.Position.Y)
    For Each dp As DataPoint In chGrupa1.Series(0).Points
        ListBox2.Items.Add(dp.XValue.ToString())
        ListBox3.Items.Add(dp.YValues(0).ToString())
    Next dp

我在互联网上找到的示例看起来像下面的代码:

'鼠标按下事件 Private Sub Chart1_MouseDown(sender As Object,e As System.Windows.Forms.MouseEventArgs)处理Chart1.MouseDown

'呼叫命中测试方法     昏暗的结果As HitTestResult = Chart1.HitTest(e.X,e.Y)

If result.ChartElementType = ChartElementType.DataPoint Then

'Create Dialog
Dim dlg As New Dialog()

'Initialize members
dlg.ChartRef = Chart1
dlg.pointIndex = result.PointIndex

' Show dialog
dlg.Show()

Else
If result.ChartElementType <> ChartElementType.Nothing Then
    Dim elementType As String = result.ChartElementType.ToString()
    MessageBox.Show(Me, "Selected Element is: " + elementType)
End If
End If

End Sub&#39; Chart1_MouseDown

&#39;鼠标移动事件 Private Sub Chart1_MouseMove(sender As Object,e As System.Windows.Forms.MouseEventArgs)处理Chart1.MouseMove

&#39;呼叫命中测试方法     昏暗的结果As HitTestResult = Chart1.HitTest(e.X,e.Y)

' If a Data Point or a Legend item is selected.
If result.ChartElementType = ChartElementType.DataPoint Or result.ChartElementType = ChartElementType.LegendItem Then
    ' Set cursor type 
    Me.Cursor = Cursors.Hand
Else
    If result.ChartElementType <> ChartElementType.Nothing And result.ChartElementType <> ChartElementType.PlottingArea Then
        ' Set cursor type 
        Me.Cursor = Cursors.Hand
    Else
        ' Set default cursor
        Me.Cursor = Cursors.Default
    End If
End If

结束子&#39; Chart1_MouseMove

对我来说,主要问题是如何确定所选区域内的哪些点以及如何获取其索引......