Option Explicit Dim ClTabChart As ClasseChart Private Sub Workbook_Open() Dim i As Integer Set ClTabChart = New ClasseChart 'Spécifie le 1er graphique de la Y.S Densité Set ClTabChart.Graph = Worksheets("Y.S Densité").ChartObjects(1).Chart Worksheets("Y.S Densité").ChartObjects(1).Activate 'désactive les intitulés et les valeurs Application.ShowChartTipNames = False Application.ShowChartTipValues = False End Sub Private Sub Workbook_BeforeClose(Cancel As Boolean) 'réactive les intitulés et les valeurs Application.ShowChartTipNames = True Application.ShowChartTipValues = True End Sub
Option Explicit Public WithEvents Graph As Chart '*** Utilisation des évènements ********* Private Sub Graph_MouseMove(ByVal Button As Long, ByVal Shift As Long, _ ByVal x As Long, ByVal y As Long) Dim ElementID As Long Dim Arg1 As Long, Arg2 As Long On Error Resume Next ActiveChart.GetChartElement x, y, ElementID, Arg1, Arg2 If Arg2 = 0 Then ActiveChart.Shapes("Rectangle 1").Visible = msoFalse Else With ActiveChart.Shapes("Rectangle 1") .Visible = msoTrue .TextFrame.Characters.Text = _ Range("C1").Offset(Arg2, -2) & vbCrLf & _ "Porosité" & "=" & Range("C1").Offset(Arg2, -1) & vbCrLf & _ "YS" & "=" & Range("C1").Offset(Arg2, 0) .Left = 0 .Top = 0 .Width = "200" .Height = "50" End With End If End Sub
Dim ClTabChart As ClasseChart
Private Sub Chart_Activate()
Set ClTabChart = New ClasseChart
'Spécifie le graphique
Set ClTabChart.Graph = ActiveChart
'désactive les intitulés et les valeurs
Application.ShowChartTipNames = False
Application.ShowChartTipValues = False
End Sub
Public WithEvents Graph As Chart
'*** Utilisation des évènements *********
Private Sub Graph_MouseMove(ByVal Button As Long, ByVal Shift As Long, _
ByVal x As Long, ByVal y As Long)
Dim ElementID As Long
Dim Arg1 As Long, Arg2 As Long
Dim Data As Worksheet
Set Data = Sheets("Données")
On Error Resume Next
ActiveChart.GetChartElement x, y, ElementID, Arg1, Arg2
If Arg2 = 0 Then
ActiveChart.Shapes("Rectangle 1").Visible = msoFalse
Else
With ActiveChart.Shapes("Rectangle 1")
.Visible = msoTrue
.TextFrame.Characters.Text = _
Data.Range("C1").Offset(Arg2, -2) & vbCrLf & _
Data.Range("C1").Offset(Arg2, -1) & vbCrLf & _
Data.Range("C1").Offset(Arg2, 0) & vbCrLf & _
Data.Range("C1").Offset(Arg2, 1) & vbCrLf & _
Data.Range("C1").Offset(Arg2, 2) & vbCrLf & _
Data.Range("C1").Offset(Arg2, 3) & vbCrLf & _
Data.Range("C1").Offset(Arg2, 4) & vbCrLf & _
Data.Range("C1").Offset(Arg2, 5) & vbCrLf & _
Data.Range("C1").Offset(Arg2, 6)
.Left = 0
.Top = 0
.Width = "200"
.Height = "150" 'ajuster la hauteur au besoin
End With
End If
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
'réactive les intitulés et les valeurs
Application.ShowChartTipNames = True
Application.ShowChartTipValues = True
End Sub
If Arg2 = 0 Thenen
If ElementID <> 3 Thencomme cela le rectangle ne s'affiche que si l'on est sur une série)
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPublic WithEvents Graph As Chart '*** Utilisation des évènements ********* Private Sub Graph_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long) Dim ElementID As Long, Arg1 As Long, Arg2 As Long, premiere_ligne_série As Long Dim Data As Worksheet Dim formule_série As String Set Data = Sheets("Données") On Error Resume Next ActiveChart.GetChartElement x, y, ElementID, Arg1, Arg2 If ElementID <> 3 Then ActiveChart.Shapes("Rectangle 1").Visible = msoFalse Else With ActiveChart.Shapes("Rectangle 1") formule_série = ActiveChart.SeriesCollection(Val(Arg1)).Formula premiere_ligne_série = Val(Split(Split(formule_série, "$")(2), ":")(0)) ligne_du_tableau = Arg2 + premiere_ligne_série - 2 .Visible = msoTrue .TextFrame.Characters.Text = _ "Colonne 1 : " & Data.Range("A1").Offset(ligne_du_tableau, 0) & vbCrLf & _ "Colonne 2 : " & Data.Range("A1").Offset(ligne_du_tableau, 1) & vbCrLf & _ "Colonne 3 : " & Data.Range("A1").Offset(ligne_du_tableau, 2) & vbCrLf & _ "Colonne 4 : " & Data.Range("A1").Offset(ligne_du_tableau, 3) & vbCrLf & _ "Colonne 5 : " & Data.Range("A1").Offset(ligne_du_tableau, 4) & vbCrLf & _ "Colonne 6 : " & Data.Range("A1").Offset(ligne_du_tableau, 5) & vbCrLf & _ "Colonne 7 : " & Data.Range("A1").Offset(ligne_du_tableau, 6) & vbCrLf & _ "Colonne 8 : " & Data.Range("A1").Offset(ligne_du_tableau, 7) & vbCrLf & _ "Colonne 9 : " & Data.Range("A1").Offset(ligne_du_tableau, 8) & vbCrLf & _ "Colonne 10 : " & Data.Range("A1").Offset(ligne_du_tableau, 9) & vbCrLf .Left = 0 .Top = 0 .Width = "300" .Height = "200" End With End If End Sub