Results 1 to 18 of 18

Thread: [RESOLVED] MSChart and mouse

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    Resolved [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.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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
    1. Put a break-point here
      • press F8 to see which branch is entered
      • I've included LaVolpe's idea as well
    2. Maybe the = "1" should be = 1
      • that is, not testing for a text string
      • but for an integer


    Spoo

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    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.

  5. #5
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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 ..

    1. Repeat what you described above.
    2. When you get to that line of code, move your mouse over Text1.Text
    3. A "tool-tip" like box should appear .. what do you get?
      • a text string
      • Empty
      • "" .. the equivalent of empty
      • something else


    Spoo

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    Re: MSChart and mouse

    Hello,
    when I move the mouse over

    MSChart1.ToolTipText = Val(Text1.Text)

    I get

    MSChart1.Tooltiptext=""

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    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.

  8. #8
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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

  9. #9
    Hyperactive Member
    Join Date
    Feb 2014
    Posts
    294

    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.

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    Re: MSChart and mouse

    Quote Originally Posted by Spooman View Post
    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


    Name:  Screen Shot 2017-09-27 at 9.49.39 AM.jpg
Views: 1598
Size:  15.8 KB

    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

  11. #11
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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

    Name:  MSChart1.png
Views: 1616
Size:  5.2 KB

    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

  12. #12
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    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

    Name:  MSChart2.png
Views: 1515
Size:  5.2 KB

    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

    Name:  MSChart3.png
Views: 1544
Size:  5.1 KB

    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.

  13. #13

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    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..........

  14. #14
    Hyperactive Member
    Join Date
    Feb 2014
    Posts
    294

    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

  15. #15
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] MSChart and mouse

    chosk

    D'oh !!
    .TwipsToChartPart .. who knew??
    You're a genius ..

    1. When I first started composing this post, I was going to say that you didn't post the code for "your" sub TwipsToChartPart
    2. Then I noticed the "." in front of that
    3. Then I checked Properties .. no luck
    4. Then I checked Methods .. bingo .. well sort of
    5. I got an error .. Type Mismatch
    6. Then I dim'd the parameters as you had .. (left out Value and Nullflag)
    7. 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)

    Name:  MSChart4.png
Views: 1506
Size:  4.7 KB

    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
    Name:  MSChart5.png
Views: 1483
Size:  5.5 KB

    Spoo
    Last edited by Spooman; Sep 28th, 2017 at 05:24 AM.

  16. #16

    Thread Starter
    Addicted Member
    Join Date
    Oct 2006
    Posts
    178

    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.

  17. #17
    PowerPoster
    Join Date
    Jun 2015
    Posts
    2,229

    Re: [RESOLVED] MSChart and mouse

    Looks like it needs a codebank submission.

  18. #18
    Fanatic Member Spooman's Avatar
    Join Date
    Mar 2017
    Posts
    868

    Re: [RESOLVED] MSChart and mouse

    Quote Originally Posted by DEXWERX View Post
    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
  •  



Click Here to Expand Forum to Full Width