gravanoc
Active Member
- Joined
- Oct 20, 2015
- Messages
- 351
- Office Version
- 365
- Platform
- Windows
- Mobile
The sizing mechanic for the plot area of my chart is acting very bizarre. If I manually click through the script a step at a time it will look like I want it to, which is like the picture below, but if I run it normally it will end up looking shrunken and off-center. Is there a way to improve my current script to make this correct regardless of those circumstances?
This is how it looks if the script is run without stepping through it:
VBA Code:
Set pieChart = coSht.Shapes.AddChart2(251, xlPie)
pieChart.ScaleWidth 1.5, msoFalse, msoScaleFromTop
pieChart.ScaleHeight 1.5, msoFalse, msoScaleFromTop
With pieChart.Chart
.SetSourceData Source:=trnRng
.ClearToMatchStyle
.ChartStyle = 257
.SetElement (msoElementChartTitleAboveChart)
With .ChartTitle
.Orientation = xlUpward
.Left = 6.954
.Top = 76
.Text = "Period: " & period
With .Format.TextFrame2.TextRange.Characters(1, .Characters.Count)
.ParagraphFormat.TextDirection = msoTextDirectionLeftToRight
.ParagraphFormat.Alignment = msoAlignCenter
With .Font
.Bold = msoTrue
.Fill.Visible = msoTrue
.Fill.ForeColor.RGB = RGB(242, 242, 242)
.Fill.Transparency = 0
.Fill.Solid
.Size = 16
.Spacing = 1
End With
End With
End With
pieChart.Chart.FullSeriesCollection(1).ApplyDataLabels
With pieChart.Chart.SeriesCollection(1).DataLabels
.Font.Size = 11
.Font.Bold = True
.Separator = WorksheetFunction.Unichar(10) & "V: "
.ShowCategoryName = True
End With
With pieChart.Chart.PlotArea
.Top = 10.8
.Left = 0
.Height = 375
End With
End With
For Each srs In pieChart.Chart.SeriesCollection
With srs
If .HasDataLabels Then
nPts = .Points.Count
aVals = .Values
For iPts = 1 To nPts
If aVals(iPts) = 0 Then
.Points(iPts).HasDataLabel = False
End If
Next
End If
End With
Next
End If
pieChart.Chart.PlotArea.Left = 125
This is how it looks if the script is run without stepping through it: