Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

ID a MSChart Piechart slice with MouseMove

$
0
0
Have you ever wanted to ID a "slice"of a MSChart PieChart by simply moving the mouse over it?

Well, here is a possible way to do so using a ToolTip.

Code:

Dim sX()

Private Sub Command1_Click()
    '
    With Command1
        .Top = 800
        .Left = 500
    End With
    With MSChart1
        .Top = 500
        .Left = 2000
        .Height = 3500
        .Width = 3000
        .Visible = True
        '
        ReDim sX(1 To 4)
        sX(1) = 1.25
        sX(2) = 2.25
        sX(3) = 3.25
        sX(4) = 5.25
        '
        .ChartData = sX
        .ChartType = VtChChartType2dPie
        .Title = "Totals Split by Acct"
        '
        .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)
    '
    Dim Part As Integer
    Dim Series As Integer
    Dim DataPoint As Integer
    Dim Index3 As Integer
    Dim Index4 As Integer
    '
    '
    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
    '
End Sub

Here is a screenshot

Name:  MSChartCB1.png
Views: 51
Size:  6.3 KB

Unfortunately, my use of Paint did not grab the mouse pointer.
However, it is in the blue slice.

Comments
  1. Truth be told, I had not used a PieChart, let alone a MSChart before encountering this thread
  2. Credit is due to starscrea2 for the basics
  3. Credit is due to chosk for pointing out the TwipsToChartPart Method
  4. Credit is due to DEXWERX for suggesting the CodeBank location.


HTH

EDIT-1

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



Spoo
Attached Images
 

Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>