[RESOLVED] MSChart and mouse
Hello,
I've been trying to program the MSChart to show data from a pie chart as tooltips, based on textbox values.
The values are different so it would be nice to see the different values when I hover the mouse over the slice.
I have tried to use the MouseMove property of MSChart with no success. In the code below, if I hover the mouse over any slice of the chart, I get a tooltip popup with the value of text1.
Code:
Private Sub MSChart1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MSChart1.ColumnLabelIndex = "1" Then
MSChart1.ToolTipText = val(text1.text)
ElseIf MSChart1.ColumnLabelIndex = "2" Then
MSChart1.ToolTipText = val(text2.text)
End If
End Sub
I tried to do a similar thing with the column property, and the tooltip does not even appear.
Code:
Private Sub MSChart1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MSChart1.Column = "1" Then
MSChart1.ToolTipText = Val(Text1.Text)
ElseIf MSChart1.Column = "2" Then
MSChart1.ToolTipText = Val(Text2.Text)
End If
I tried to RTF the M for MsChart.hlp but couldn't find any samples or explanations for how to do this behavior.
I looked for samples online, and looked for samples here as well, but didn't find anything.
Does anyone know how to do this?
Please let me know. Thank you for any feedback.
Re: [RESOLVED] MSChart and mouse
I managed to get the ToolTipText to show the value on MouseMove. I know this is not the "proper" way as I cannot get the second part to work - the .GetData is giving me Run-time error "1101': Bad function argument. If working, Value will go into ToolTipText.
Code:
Option Explicit
Private Data(1 To 4) As Variant
Private Sub Command2_Click()
'Dim Data(1 To 4) As Variant
Text1.Text = "1.25"
Text2.Text = "2.25"
Text3.Text = "3.25"
Text4.Text = "5.25"
'Text values
Data(1) = Val(Text1.Text)
Data(2) = Val(Text2.Text)
Data(3) = Val(Text3.Text)
Data(4) = Val(Text4.Text)
'Assign Textvalues to Chart control
MSChart1.ChartData = Data
MSChart1.Title = "Totals Split by Financial Institution"
'add labels to the columns
MSChart1.Column = 1
MSChart1.ColumnLabel = "BankAccount1"
MSChart1.Column = 2
MSChart1.ColumnLabel = "BankAccount2"
MSChart1.Column = 3
MSChart1.ColumnLabel = "BankAccount3"
MSChart1.Column = 4
MSChart1.ColumnLabel = "BankAccount4"
End Sub
Private Sub MSChart1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim Part As Integer
Dim Series As Integer
Dim DataPoint As Integer
Dim Index3 As Integer
Dim Index4 As Integer
Dim Value As Double
Dim NullFlag As Integer
With MSChart1
.TwipsToChartPart X, Y, Part, Series, DataPoint, Index3, Index4
If (Part = VtChPartTypeSeries) Then .ToolTipText = Data(Series)
'If (Part = VtChPartTypeSeries) Then
' .DataGrid.GetData DataPoint, Series, Value, NullFlag
' .ToolTipText = Value
'Else
' .ToolTipText = "ouch"
'End If
End With
End Sub
2 Attachment(s)
Re: [RESOLVED] MSChart and mouse
chosk
D'oh !!
.TwipsToChartPart .. who knew??
You're a genius .. :thumb:
- When I first started composing this post, I was going to say that you didn't post the code for "your" sub TwipsToChartPart
- Then I noticed the "." in front of that
- Then I checked Properties .. no luck
- Then I checked Methods .. bingo .. well sort of
- I got an error .. Type Mismatch
- Then I dim'd the parameters as you had .. (left out Value and Nullflag)
- Then .. BINGO
Code:
Private Sub MSChart1_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
'
Dim Part As Integer
Dim Series As Integer
Dim DataPoint As Integer
Dim Index3 As Integer
Dim Index4 As Integer
'
Dim sX(1 To 4)
sX(1) = "1.25"
sX(2) = "2.25"
sX(3) = "3.25"
sX(4) = "5.25"
'
With MSChart1
.TwipsToChartPart X, Y, Part, Series, DataPoint, Index3, Index4
If Series > 0 Then
txt = .ColumnLabel
.ToolTipText = txt & " ... " & sX(Series)
End If
End With
'
End Sub
.. and got this (mouse hovering in blue slice)
Attachment 152305
I noticed that if the mouse is over the control (within the border but not on a slice)
- I got a Tooltip for Series 0
- so I added the test If Series > 0 Then
EDIT-1
Oops .. wrong ColumnLabel
Needed to add this
Code:
With MSChart1
.TwipsToChartPart X, Y, Part, Series, DataPoint, Index3, Index4
If Series > 0 Then
.Column = Series
txt = .ColumnLabel
.ToolTipText = txt & " ... " & sX(Series)
End If
End With
Attachment 152307
Spoo
Re: [RESOLVED] MSChart and mouse
This may be a dumb question, but is there any way to edit the title of this thread to be "Showing MSChart values using Mousemove " or something similar?
When I was looking for a solution, I saw a lot of other people were looking for this as well. It might help anyone in the future who is still using MsChart and VB6, who wants to add pie chart values.
Re: [RESOLVED] MSChart and mouse
Looks like it needs a codebank submission.
Re: [RESOLVED] MSChart and mouse
Quote:
Originally Posted by
DEXWERX
Looks like it needs a codebank submission.
Done ... here