4,816
社区成员
发帖
与我相关
我的任务
分享
Private Sub Chart1_PostPaint(sender As Object, e As System.Windows.Forms.DataVisualization.Charting.ChartPaintEventArgs) Handles Chart1.PostPaint
If TypeOf sender Is ChartArea Then
Dim area As ChartArea = CType(sender, ChartArea)
If area.Name = "Default" Then
' If Connection line is not checked return
If Not ConnectionLine.Checked Then
Return
End If
Dim max As Double
Dim min As Double
Dim xMax As Double
Dim xMin As Double
' Find Minimum and Maximum values
FindMaxMin(max, min, xMax, xMin)
' Get Graphics object from chart
Dim graph As Graphics = e.ChartGraphics.Graphics
' Convert X and Y values to screen position
Dim pixelYMax As Single = CSng(e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, max))
Dim pixelXMax As Single = CSng(e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, xMax))
Dim pixelYMin As Single = CSng(e.ChartGraphics.GetPositionFromAxis("Default", AxisName.Y, min))
Dim pixelXMin As Single = CSng(e.ChartGraphics.GetPositionFromAxis("Default", AxisName.X, xMin))
Dim point1 As PointF = PointF.Empty
Dim point2 As PointF = PointF.Empty
' Set Maximum and minimum points
point1.X = pixelXMax
point1.Y = pixelYMax
point2.X = pixelXMin
point2.Y = pixelYMin
' Convert relative coordinates to absolute coordinates.
point1 = e.ChartGraphics.GetAbsolutePoint(point1)
point2 = e.ChartGraphics.GetAbsolutePoint(point2)
' Draw connection line
graph.DrawLine(New Pen(Color.Yellow, 3), point1, point2)
End If
End If
End Sub