|
-
Sep 26th, 2017, 04:12 PM
#1
Thread Starter
Addicted Member
[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.
-
Sep 26th, 2017, 04:27 PM
#2
Re: MSChart and mouse
I tried to do a similar thing with the column property, and the tooltip does not even appear.
Maybe MSchart1.Column is not = 1 nor 2? Try adding an ELSE statement also to test it
Code:
If ...
ElseIf ...
Else
End If
-
Sep 26th, 2017, 07:43 PM
#3
Re: MSChart and mouse
Star
Code:
If MSChart1.ColumnLabelIndex = "1" Then
MSChart1.ToolTipText = val(text1.text)
ElseIf MSChart1.ColumnLabelIndex = "2" Then
MSChart1.ToolTipText = val(text2.text)
Else
b = b
End If
A couple of thoughts
- Put a break-point here
- press F8 to see which branch is entered
- I've included LaVolpe's idea as well
- Maybe the = "1" should be = 1
- that is, not testing for a text string
- but for an integer
Spoo
-
Sep 26th, 2017, 09:28 PM
#4
Thread Starter
Addicted Member
Re: MSChart and mouse
Thank you. Testing for an integer makes way more sense than testing for a text string.
I changed the "1" and "2" to 1 and 2 to see if that would correct the issue. Unfortunately, it does not.
When I put the breakpoint here If MSChart1.ColumnLabelIndex = "1" Then
The editor highlighted
If MSChart1.ColumnLabelIndex = 1 Then
Pressing F8 it goes down to:
MSChart1.ToolTipText = Val(Text1.Text)
and then finally, pressing F8 it goes down again, to the final End If.
-
Sep 27th, 2017, 03:36 AM
#5
Re: MSChart and mouse
Star
OK, that's progress
Although I must admit that I'm a little surprised that both "1" and 1 are accepted.
Anyway, we're now at this line
MSChart1.ToolTipText = Val(Text1.Text)
I'm suspicious of the Val() function, but here is a quick test you can do ..
- Repeat what you described above.
- When you get to that line of code, move your mouse over Text1.Text
- A "tool-tip" like box should appear .. what do you get?
- a text string
- Empty
- "" .. the equivalent of empty
- something else
Spoo
-
Sep 27th, 2017, 08:04 AM
#6
Thread Starter
Addicted Member
Re: MSChart and mouse
Hello,
when I move the mouse over
MSChart1.ToolTipText = Val(Text1.Text)
I get
MSChart1.Tooltiptext=""
-
Sep 27th, 2017, 08:37 AM
#7
Thread Starter
Addicted Member
Re: MSChart and mouse
I tried putting 2 VSFlexgrid controls on the form and passing the textbox values to the VSFlexgrids to see if it was the textbox that was the issue with reading the values. VSFlexgrid has a Textmatrix and a Valuematrix property, so I tried both.
Code:
Private Sub MSChart1_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MSChart1.ColumnLabelIndex = 1 Then
MSChart1.ToolTipText = VSFlexGrid1.TextMatrix(1, 1)
ElseIf MSChart1.ColumnLabelIndex = 2 Then
MSChart1.ToolTipText = VSFlexGrid2.TextMatrix(1, 1)
Else
b = b
End If
End Sub
But the result is the same: MsChart1.Tooltiptext=""
Last edited by starscrea2; Sep 27th, 2017 at 08:41 AM.
-
Sep 27th, 2017, 09:34 AM
#8
Re: MSChart and mouse
Star
Well, we've made some progress, but sadly only to determine that the Tooltiptext = "" (ie, effectively empty)
Could you post the code snippet wherein you create your chart, and a screenshot thereof.
Spoo
-
Sep 27th, 2017, 10:30 AM
#9
Hyperactive Member
Re: MSChart and mouse
The last time I program for MSChart was loong time ago. I remember you have to take the mouse X and Y positions and convert it to what or where it is moving over and then get the relevant data to put into the tooltip. I just did a quick check and see a .TwipsToChartPart and this look like the place to go to find your solution.
Edit
Just remember I was doing line chart then. So maybe I am talking nonsense. Sorry if I am.
Last edited by chosk; Sep 27th, 2017 at 10:39 AM.
-
Sep 27th, 2017, 11:52 AM
#10
Thread Starter
Addicted Member
Re: MSChart and mouse
 Originally Posted by Spooman
Star
Well, we've made some progress, but sadly only to determine that the Tooltiptext = "" (ie, effectively empty)
Could you post the code snippet wherein you create your chart, and a screenshot thereof.
Spoo

Code:
Private Sub Command2_Click()
Dim X(1 To 4) As Variant
'Text values
X(1) = Val(Text1.Text)
X(2) = Val(Text2.Text)
X(3) = Val(Text3.Text)
X(4) = Val(Text4.Text)
Text1.Text = "1.25"
Text2.Text = "2.25"
Text3.Text = "3.25"
Text4.Text = "5.25"
'Assign Textvalues to Chart control
MSChart1.ChartData = X
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
-
Sep 27th, 2017, 01:37 PM
#11
Re: MSChart and mouse
Star
OK. I've made some progress
BTW, in case you hadn't guessed, I've never used MSChart before .. 
Code:
Private Sub Command1_Click()
With MSChart1
Dim sX(1 To 4)
sX(1) = "1.25"
sX(2) = "2.25"
sX(3) = "3.25"
sX(4) = "5.25"
.ChartData = sX
.ChartType = VtChChartType2dPie
.Column = 1
.ColumnLabel = "Acct 1"
.Column = 2
.ColumnLabel = "Acct 2"
.Column = 3
.ColumnLabel = "Acct 3"
.Column = 4
.ColumnLabel = "Acct 4"
End With
End Sub
Private Sub MSChart1_Mousemove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If MSChart1.ColumnLabelIndex = 1 Then
MSChart1.ToolTipText = "ToolTip = 1"
ElseIf MSChart1.ColumnLabelIndex = 2 Then
MSChart1.ToolTipText = 2
Else
b = b
End If
End Sub
Here is a screenshot

No matter where the mouse is, I always get that tool-tip
In this case, the mouse was hovering over "R1" .. ie, NOT even on the pie-chart.
I'll look into this a bit more and report.
Spoo
-
Sep 27th, 2017, 04:09 PM
#12
Re: MSChart and mouse
Star
Made a little more progress
Code:
Private Sub Command1_Click()
With MSChart1
Dim sX(1 To 4)
sX(1) = "1.25"
sX(2) = "2.25"
sX(3) = "3.25"
sX(4) = "5.25"
.ChartData = sX
.ChartType = VtChChartType2dPie
.Column = 1
.ColumnLabel = "Acct 1"
.Column = 2
.ColumnLabel = "Acct 2"
.Column = 3
.ColumnLabel = "Acct 3"
.Column = 4
.ColumnLabel = "Acct 4"
End With
End Sub
Private Sub MSChart1_SeriesSelected(Series As Integer, MouseFlags As Integer, Cancel As Integer)
'
With MSChart1
.Column = Series
txt = .ColumnLabel
.ToolTipText = txt
End With
'
End Sub
- The first sub is unchanged from my earlier post
- The second sub is all new
.. and the image

In this case, I clicked the blue slice.
Note that this requires a Click, and the sub MSChart1_SeriesSelected() is triggered.
MouseMove() didn't seem to do the trick.
Hope this is close enough.
Natch, modify the tool-tip text as needed.
EDIT-1
Got a little fancier with the tool-tip
Code:
Private Sub MSChart1_SeriesSelected(Series As Integer, MouseFlags As Integer, Cancel 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
.Column = Series
txt = .ColumnLabel
.ToolTipText = txt & vbCrLf & sX(Series) ' << didn't accept two line tip
.ToolTipText = txt & " ... " & sX(Series)
End With
'
End Sub
.. and get this

I had to repeat the sX() dim and set's as the former was not set in Declarations
Couldn't get vbCrLf to do anything
Spoo
Last edited by Spooman; Sep 27th, 2017 at 04:21 PM.
-
Sep 27th, 2017, 05:50 PM
#13
Thread Starter
Addicted Member
Re: MSChart and mouse
Thank you! This works. I will do some conditional formatting to get the account names to match up, and I think we have it!
Thanks again! I appreciate it. I was losing sleep over this..........
-
Sep 27th, 2017, 09:31 PM
#14
Hyperactive Member
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
Last edited by chosk; Sep 27th, 2017 at 10:03 PM.
Reason: Paste the wrong codes
-
Sep 28th, 2017, 05:14 AM
#15
Re: [RESOLVED] MSChart and mouse
chosk
D'oh !!
.TwipsToChartPart .. who knew??
You're a genius .. 
- 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)

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

Spoo
Last edited by Spooman; Sep 28th, 2017 at 05:24 AM.
-
Sep 28th, 2017, 07:23 AM
#16
Thread Starter
Addicted Member
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.
-
Sep 28th, 2017, 08:36 AM
#17
Re: [RESOLVED] MSChart and mouse
Looks like it needs a codebank submission.
-
Sep 28th, 2017, 09:21 AM
#18
Re: [RESOLVED] MSChart and mouse
 Originally Posted by DEXWERX
Looks like it needs a codebank submission.
Done ... here
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|