chart-creation-code
chart-creation-code
'Add count
.AddDataField .PivotFields("Assembly/ Part"), "Count of Parts", xlCount
'Create chart
Set pvtChart = wsChart.ChartObjects.Add( _
Left:=wsChart.Range("A3").Left, _
Top:=wsChart.Range("A3").Top, _
Width:=900, Height:=400)
With pvtChart.Chart
.SetSourceData Source:=pvtTable.TableRange2
.ChartType = xlBarClustered
With .SeriesCollection(2)
.HasDataLabels = True
.DataLabels.ShowValue = True
.DataLabels.Position = xlOutsideEnd
.Format.Fill.ForeColor.RGB = RGB(255, 0, 0) 'Red for Shortage
End With
'Remove legend
.HasLegend = False
End With
With slcCache.Slicers.Add( _
wsChart, , "Buyers", "Select Buyers", 10, 10, 200, 300)
.Style = "SlicerStyleLight1"
.Caption = "Select Buyers"
End With
'Cleanup
wsChart.Activate
pvtTable.ShowTableStyleRowStripes = True
wsChart.Range("A1").Select