用 C++ 判断数据点是否位于饼图中的第二个饼或条形图中的条上

可能的使用场景

你可以使用 Aspose.Cells 判断系列的数据点是否在 Pie of Pie 图表的第二个饼或 Bar of Pie 图表的条中。请使用 ChartPoint.IsInSecondaryPlot 属性判断。

请下载以下示例代码中使用的样本excel文件,并查看其控制台输出。如果您打开样本excel文件,您会发现所有小于10的数据点都在饼图的柱状图中,正如控制台输出所示。

查找数据点是否在饼图的第二个饼图或柱状图的柱状图上

以下示例代码显示了如何查看数据点是否在饼图的第二个饼图上,或者在柱状图的柱状图上。

#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace Aspose::Cells::Charts;

int main()
{
    Aspose::Cells::Startup();

    U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
    U16String inputFilePath = srcDir + u"PieBars.xlsx";
    Workbook workbook(inputFilePath);

    Worksheet worksheet = workbook.GetWorksheets().Get(0);

    Chart chart = worksheet.GetCharts().Get(0);
    chart.Calculate();

    Series series = chart.GetNSeries().Get(0);

    int pointCount = series.GetPoints().GetCount();
    for (int i = 0; i < pointCount; ++i)
    {
        ChartPoint chartPoint = series.GetPoints().Get(i);

        if (chartPoint.Get_YValue().IsNull())
            continue;

        std::cout << "Value: " << chartPoint.Get_YValue().ToDouble() << std::endl;
        std::cout << "IsInSecondaryPlot: " << (chartPoint.IsInSecondaryPlot() ? "true" : "false") << std::endl;
        std::cout << std::endl;
    }

    Aspose::Cells::Cleanup();
    return 0;
}

控制台输出

请查看在执行上述示例代码后生成的控制台输出(包含示例Excel文件)。如果 IsInSecondaryPlotfalse,则数据点位于饼图内部;若为 true,则数据点位于条中。

 Value: 15

IsInSecondaryPlot: False

Value: 9

IsInSecondaryPlot: True

Value: 2

IsInSecondaryPlot: True

Value: 40

IsInSecondaryPlot: False

Value: 5

IsInSecondaryPlot: True

Value: 4

IsInSecondaryPlot: True

Value: 25

IsInSecondaryPlot: False