gravanoc
Active Member
- Joined
- Oct 20, 2015
- Messages
- 351
- Office Version
- 365
- Platform
- Windows
- 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