1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
Imports System.Windows.Forms.DataVisualization.Charting
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim x As Double
Dim y As Double
For index = -100 To 100
y = Math.Cos(x)
x += 2 * Math.PI / 100
Chart1.Series(0).Points.AddXY(x, y)
Next
End Sub
Private Sub Chart1_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Chart1.MouseMove
' Appel HitTest qui retourne l'objet sous le curseur
Dim result As HitTestResult = Chart1.HitTest(e.X, e.Y)
' Remet sur toute la series les attributs normaux
Dim point As DataPoint
For Each point In Chart1.Series(0).Points
point.BorderWidth = 2
'supprimez le commentaire pour voir la diffrence
'avec couleur dont aplha <> 0
'point.Color = Color.FromArgb(155, Color.Red)
Next
' Si la souris est sur un data point
If result.ChartElementType = ChartElementType.DataPoint And result.PointIndex <> -1 Then
' Chercher quel data point dans la series
Dim point1 As DataPoint = Chart1.Series(0).Points(result.PointIndex)
' Changer l'apparence du data point survolé
point1.Color = Darken(point1.Color, 50)
point1.BorderWidth = 8
Me.Cursor = Cursors.Hand
Else
' Curseur par défaut
Me.Cursor = Cursors.Default
End If
End Sub
Function Darken(ByVal Col As Color, ByVal Percent As Integer) As Color
Dim R, G, B As Byte
Console.WriteLine(Col.A.ToString)
R = CType(Col.R * Percent / 100, Byte)
G = CType(Col.G * Percent / 100, Byte)
B = CType(Col.B * Percent / 100, Byte)
Return Color.FromArgb(Col.A, R, G, B)
End Function
End Class |
Partager