Pie Charts - Any way to have majority slice always on top? (1 Viewer)

boblarson

Smeghead
Local time
Today, 12:15
Joined
Jan 12, 2001
Messages
32,059
I don't think this is possible but one of the higher-ups has requested that for this report all of the pie charts show the slice with the highest percentage be on top (I've told the lower person who gave the request to me as a go-between that I didn't think it was possible with Access but I thought I'd put the question out there just in case there was).

See the screenshot below. The lower left one would have the blue on top and the others shifted around, if they can get what they want.

 

Attachments

  • GraphSlicesQuestion.png
    GraphSlicesQuestion.png
    10.1 KB · Views: 223

the_net_2.0

Banned
Local time
Today, 14:15
Joined
Sep 6, 2010
Messages
812
Bob,

you've shown them the broken pie charts, right? First thing that came to mind, personally, was to use that one and shift the largest section via code. That's ridiculous I know, but like I said, it came to mind.

Hopefully it proves useful is coming to some sort of answer!
 

ChrisO

Registered User.
Local time
Tomorrow, 05:15
Joined
Apr 30, 2003
Messages
3,202
Code:
Private Sub cmdTestIt_Click()

    [color=green]' Some how figure out how much it needs rotating.
    ' Assume 90 deg. clockwise.[/color]
    RotateChart "chtMyPie", 90

End Sub


Private Sub RotateChart(ByVal strChartName As String, _
                        ByVal lngAngle As Long)
                        
    Dim lngOldType As Long

    [color=green]' User doesn’t need to see this.[/color]
    Application.Echo False
    
    With Me(strChartName)
        [color=green]' Get current 2D type, should be 5.[/color]
        lngOldType = .ChartType
        [color=green]' Set to 3D Pie.[/color]
        .ChartType = -4102
        [color=green]' Rotate the 3D Pie.[/color]
        .Rotation = .Rotation + lngAngle
        [color=green]' Reset to 2D Pie.[/color]
        .ChartType = lngOldType
    End With
    
    [color=green]' Let them see the result.[/color]
    Application.Echo True
    
End Sub

HTH.

Chris.
 
Last edited:

vbaInet

AWF VIP
Local time
Today, 20:15
Joined
Jan 22, 2010
Messages
26,374
Perhaps another way would be to sort the records in ASC order and set the first slice angle at 90 deg:
Code:
    Const strSQL As String = "SELECT ... FROM ... "
    
    With Me.[COLOR=Red]NameOfChart
        [/COLOR].SetEchoOn False

        .RowSource = strSQL & " ORDER BY [Field];"
        
        .ChartType = xl3DPie
    
        .Pie3DGroup.FirstSliceAngle = [COLOR=Red]90[/COLOR]
        
        .ChartType = 5
    
        .SetEchoOn True
    End With
This will ensure that the smallest percentage starts at the bottom which will in turn cause the highest percentage to stay on top.

If you want to refine this, then you can set the FirstSliceAngle based on the value of the highest percentage. E.g. if the max percentage = 40% then you probably want an angle of 45 (or thereabouts), if it's >= 50% then 90 is good.

I'm sure once you have it working you will convert it to a function so it's re-usable.
 

ChrisO

Registered User.
Local time
Tomorrow, 05:15
Joined
Apr 30, 2003
Messages
3,202
As a bit of a cleanup that may prove useful.

We can calculate precisely where the top of the largest slice should be.

The angle of rotation required is based on the total of the preceding slices plus the mid-point of the largest slice, divided by the total value of the pie.

2D + 3D + Report: A2003 demo attached, no references required.

Chris.
 

Attachments

  • RotatePieGraphs_A2003.zip
    31.7 KB · Views: 72

boblarson

Smeghead
Local time
Today, 12:15
Joined
Jan 12, 2001
Messages
32,059
Thanks Chris, I will take a look and see if I can incorporate that into my report. They are happy enough with what I ended up with but they would probably be even happier if I managed to get it to work exactly as they had desired. :)
 

ChrisO

Registered User.
Local time
Tomorrow, 05:15
Joined
Apr 30, 2003
Messages
3,202
No problems, Bob, it was an interesting project.

It is also not a bad idea to spin the largest to the top.
If we had a number of slices that were so close together in value it could be difficult to see which is the largest.

The only way would be to read the values and that might place too much stress on management. :rolleyes:
So management came up with an idea to reduce stress on them by placing the stress on you. ;)

I guess that’s management. :D

Chris.
 

Users who are viewing this thread

Top Bottom