Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 基于原始数字的自定义图表数据标签,而不是%_Excel_Charts_Pivot Table_Excel Charts_Vba - Fatal编程技术网

Excel 基于原始数字的自定义图表数据标签,而不是%

Excel 基于原始数字的自定义图表数据标签,而不是%,excel,charts,pivot-table,excel-charts,vba,Excel,Charts,Pivot Table,Excel Charts,Vba,我有一个数据透视图,显示字段的%作为值,但我希望标签是%和%所基于的运行数的组合 当前: 我想要的是: %这个数字很简单,因为当我循环遍历data seriescollection时,我可以从中获取值,但我不知道如何获取数据中的数字 我可以对原始数据集~7000行进行计数以获得数字,但这意味着我需要两行轴项目的当前值 那么,当我在序列集合点中循环时,有没有办法得到轴字段中两个项目的值 例如,当我在16.86点时,我可以得到响应值和无评论/无响应值,这样我就可以计算出标签中的数字。如果你点击标签,

我有一个数据透视图,显示字段的%作为值,但我希望标签是%和%所基于的运行数的组合

当前:

我想要的是:

%这个数字很简单,因为当我循环遍历data seriescollection时,我可以从中获取值,但我不知道如何获取数据中的数字

我可以对原始数据集~7000行进行计数以获得数字,但这意味着我需要两行轴项目的当前值

那么,当我在序列集合点中循环时,有没有办法得到轴字段中两个项目的值


例如,当我在16.86点时,我可以得到响应值和无评论/无响应值,这样我就可以计算出标签中的数字。如果你点击标签,按=键,然后将其指向一个单元格,它将显示你指向的单元格的值。你应该制作一个辅助单元格来实现这一点,它可以按照你想要的方式格式化值。

看起来我已经得到了我自己问题的答案。我开始在数据透视字段中循环,跳过不需要的数据透视字段,然后在循环过程中更新点

以下是我所做工作的示例:

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

问题是数据透视表和图表需要动态更新,这就是我选择vba路线的原因。读取失败。我给我的房子带来了耻辱。不用担心,我认为从1到点数的循环,然后尝试从seriescollection中的XValues获取数据可能会起作用,但我无法从XValues获取正确读取的数据数据透视有时是从中检索数据的有趣的东西。你必须使用PT吗?您可以设置sumif范围集吗?