Doughnut chart in Gauge chart not always set to correct axis group

gravanoc

Active Member
Joined
Oct 20, 2015
Messages
351
Office Version
  1. 365
Platform
  1. Windows
  2. Mobile
I'm using a few generated gauge charts that are combination pie & donut charts. To display correctly, the donut needs to be plotted on the secondary axis, but it seems completely random as to whether the code enforces that or not, so it ends up failing at the part where it references a point that is not in its series collection. It would be part of the collection if it was plotted correctly, but it seems to ignore my AxisGroup setting. Usually to fix this I have to restart Excel, but I'd prefer to know if there's another way.

VBA Code:
Sub ChartSetup(shpChart As Shape, rngFormula As Range)
    
    With shpChart
        .Height = 210
        .Width = 210
        
        With .Chart
            .HasTitle = True
            .SetElement (msoElementChartTitleCenteredOverlay)
            .SetElement (msoElementLegendNone)
            
            With .FullSeriesCollection(1)
                .ChartType = xlDoughnut
                .AxisGroup = 2  ' This should cause this FSC to be plotted on the secondary axis, but does not always work.
                
                shpChart.Chart.ChartGroups(1).DoughnutHoleSize = 70
                shpChart.Chart.ChartGroups(1).FirstSliceAngle = 270
                
                With .Points(1).Format.Fill
                    .ForeColor.RGB = RGB(139, 0, 0)
                    .TwoColorGradient msoGradientVertical, 1
                    .GradientStops(2).Color.RGB = RGB(0, 128, 0)
                    .GradientStops.Insert RGB(255, 0, 0), 0.15
                    .GradientStops.Insert RGB(255, 165, 0), 0.3
                    .GradientStops.Insert RGB(255, 255, 0), 0.5
                    .GradientStops.Insert RGB(144, 238, 144), 0.75
                End With
                
                .Points(1).Format.Line.ForeColor.RGB = RGB(0, 0, 0)
                .Points(4).Format.Fill.Visible = msoFalse
                .Points(4).Format.Line.Visible = msoFalse  ' Error occurs here sometimes
            End With
            
            With .FullSeriesCollection(2)
                .ChartType = xlPie
                shpChart.Chart.ChartGroups(1).FirstSliceAngle = 270
                
                .Points(1).Format.Fill.Visible = msoFalse
                .Points(1).Format.Line.Visible = msoFalse
                .Points(2).Format.Fill.ForeColor.RGB = RGB(0, 0, 0)
                .Points(2).Format.Line.ForeColor.RGB = RGB(0, 0, 0)
                .Points(3).Format.Fill.Visible = msoFalse
                .Points(3).Format.Line.Visible = msoFalse
            End With
            
            shpChart.Chart.FullSeriesCollection(1).AxisGroup = 1
            shpChart.Chart.FullSeriesCollection(2).AxisGroup = 2
            
            
            With .ChartTitle
                
                DoEvents
                .Formula = "=" & rngFormula.Parent.Name & "!" & rngFormula.Address
                
                With .Format
                    .Fill.ForeColor.RGB = RGB(50, 50, 50)
                    .Line.ForeColor.RGB = RGB(80, 184, 192)
                    .Line.Weight = 1.75

                    With .TextFrame2.TextRange
                        .ParagraphFormat.Alignment = msoAlignCenter
                        .Font.Bold = msoTrue
                        .Font.Name = "Biome"
                        .Font.Size = 14
                        .Font.Fill.ForeColor.RGB = RGB(255, 255, 255)
                    End With
                
                End With
                
                .Top = .Top + 125
                .Formula = "=" & rngFormula.Parent.Name & "!" & rngFormula.Address
                .Left = .Left - 12.5
            End With
            
            
        End With
    End With
    
'    Stop
'    shpChart.Delete
    
End Sub
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,223,880
Messages
6,175,155
Members
452,615
Latest member
bogeys2birdies

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top