查找数据点是否位于饼图饼图或饼图条形图的第二个饼图或条形图中

可能的使用场景

您可以找到系列的数据点是否在第二个饼图中馅饼的馅饼图表或在栏中馅饼吧使用 Aspose.Cells 的图表。请使用ChartPoint.IsInSecondaryPlot属性来确定它。

请下载示例 excel 文件在以下示例代码中使用并查看其控制台输出。如果你打开示例 excel 文件 ,你会发现,所有小于10的数据点都在馅饼吧图表也由控制台输出显示。

查找数据点是否位于饼图饼图或饼图条形图的第二个饼图或条形图中

以下示例代码显示如何查找数据点是否在第二个饼图或条形图中馅饼的馅饼要么馅饼吧图表。

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
//Load source excel file containing Bar of Pie chart
Workbook wb = new Workbook(dataDir + "PieBars.xlsx");
// Access first worksheet
Worksheet ws = wb.Worksheets[0];
// Access first chart which is Bar of Pie chart and calculate it
Chart ch = ws.Charts[0];
ch.Calculate();
// Access the chart series
Series srs = ch.NSeries[0];
/*
* Print the data points of the chart series and
* check its IsInSecondaryPlot property to determine
* if data point is inside the bar or pie
*/
for (int i = 0; i < srs.Points.Count; i++)
{
//Access chart point
ChartPoint cp = srs.Points[i];
//Skip null values
if (cp.YValue == null)
continue;
/*
* Print the chart point value and see if it is inside bar or pie.
* If the IsInSecondaryPlot is true, then the data point is inside bar
* otherwise it is inside the pie.
*/
Console.WriteLine("Value: " + cp.YValue);
Console.WriteLine("IsInSecondaryPlot: " + cp.IsInSecondaryPlot);
Console.WriteLine();
}

控制台输出

请查看执行上述示例代码后生成的以下控制台输出示例 excel 文件.如果位于次要情节错误的 数据点在 Pie 内部或者如果它在真的那么数据点就在 Bar 里面。

 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