AW: Beispieldatei
09.04.2009 11:53:53
ChristsianM
Hallo,
im folgenden Beispiel wird ein Shape rechts oben im Diagramm erzeugt. Beim Mousemove-Ereignis über einen Datenpunkt werden die Infos aus Tabelle1 in diesem Shape angezegt.
Aktiviert wird das ganze, wenn das Diagramm-Sheet aktiviert wird (zB beim Wechsel von einer Tabelle zu dem Diagramm). Der Code muss ins Klassenmodul von Diagramm1.
Gruß
Christian
Option Explicit
Private Const SHNAME As String = "ChartTip"
Dim shInfo As Shape
Private Sub Chart_Activate()
Dim sh As Shape
For Each sh In ActiveChart.Shapes
If sh.Name = SHNAME Then
sh.Delete
Set shInfo = Nothing
End If
Next
With ActiveChart
Set shInfo = .Shapes.AddShape(1, .ChartArea.Width - 100, .ChartArea.Top + 10, 80, 50)
shInfo.Name = SHNAME
End With
End Sub
Private Sub Chart_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y _
_
As Long)
Dim lngElmt&, lngSer&, lngPnt&
Dim strTxt As String
Dim varX, varRow
With Sheets("Tabelle1")
ActiveChart.GetChartElement x, y, lngElmt, lngSer, lngPnt
If Not shInfo Is Nothing Then
If lngElmt xlSeries Then shInfo.TextFrame.Characters.Text = "": Exit Sub
End If
If lngPnt > 0 Then
varX = Application.Index(ActiveChart.SeriesCollection(lngSer).XValues, lngPnt)
varRow = Application.Match(CDbl(varX), .Columns(3), 0)
strTxt = _
.Cells(varRow, 1) & vbLf & _
"ICAO: " & .Cells(varRow, 2) & vbLf & _
"N: " & .Cells(varRow, 3) & vbLf & _
"E: " & .Cells(varRow, 4)
If Not shInfo Is Nothing Then
shInfo.TextFrame.Characters.Text = strTxt
shInfo.TextFrame.Characters.Font.Size = 8
End If
End If
End With
End Sub