查找数据点是否在饼图的第二个饼图或柱状图的柱状图上
Contents
[
Hide
]
可能的使用场景
您可以使用Aspose.Cells来查找系列的数据点是否位于饼图的饼图或者条状饼图的第二个饼图中。请使用ChartPoint.IsInSecondaryPlot属性来确定。
请下载以下示例代码中使用的样本excel文件,并查看其控制台输出。如果您打开样本excel文件,您会发现所有小于10的数据点都在饼图的柱状图中,正如控制台输出所示。
查找数据点是否在饼图的第二个饼图或柱状图的柱状图上
以下示例代码显示了如何查看数据点是否在饼图的第二个饼图上,或者在柱状图的柱状图上。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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文件。如果IsInSecondaryPlot为false,则数据点在饼图内,如果为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