看来我得到了自己问题的答案。我完成了循环遍历枢轴场并跳过不需要的那些,然后在循环期间更新点。
这是我所做的一个示例:
Set WSpt = Sheets("PivotTablesSheet")
Set pt = WSpt.PivotTables("PivotTableName")
Set pf = pt.PivotFields("FieldName")
F = pt.PivotFields("FilterName").CurrentPage.Name 'if Needed
Vals = Cht.SeriesCollection(1).Values 'Values of the chart because you can not work with them directly :(
Set LR = WSpt.Cells(pf.DataRange.Row, pf.DataRange.Column) 'First Cell in Field DataRange
'loop through cells in FieldName DataRange
For i = 1 To pf.DataRange.Cells.Count
'Put in check to see if the cell that was currently being checked was part of the primary field or the secondary one (only needed because I had a multi-level field setup
On Error Resume Next
tmp = pt.PivotFields("Main").PivotItems(LR.Value)
If Err.Number = 0 Then
Q = LR.Value
Set LR = LR.Offset(1, 0)
i = i - 1
Else
RC = LR.Value
Set LR = LR.Offset(1, 0)
'change formula to get the number value based on if the "(All)" option was selected or if just some items in the table need to be counted
If F = "(All)" Then
'Save Results of CountIF in the NUM variable
Num = Application.WorksheetFunction.CountIfs(Sheets("DataSheet").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("Main").DataBodyRange.Address), Q, _
Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("FieldName").DataBodyRange.Address), RC)
Else
Num = Application.WorksheetFunction.CountIfs(Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("FilterName").DataBodyRange.Address), F, _
Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("Main").DataBodyRange.Address), Q, _
Sheets("Data").Range(Sheets("DataSheet").ListObjects("DataTBL").ListColumns("FieldName").DataBodyRange.Address), RC)
End If
Cht.SeriesCollection(1).Points(i).DataLabel.Text = FormatPercent(Vals(i), 1) & " (" & Num & ")"
Cht.SeriesCollection(1).Points(i).DataLabel.Orientation = xlUpward
End If
Next i
End Sub