查找数据点是否在饼图的第二个饼图或柱状图的柱状图上
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-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getSharedDataDir(FindDataPoints.class) + "articles/"; | |
// Load source excel file containing Bar of Pie chart | |
Workbook wb = new Workbook(dataDir + "PieBars.xlsx"); | |
// Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
// Access first chart which is Bar of Pie chart and calculate it | |
Chart ch = ws.getCharts().get(0); | |
ch.calculate(); | |
// Access the chart series | |
Series srs = ch.getNSeries().get(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.getPoints().getCount(); i++) { | |
// Access chart point | |
ChartPoint cp = srs.getPoints().get(i); | |
// Skip null values | |
if (cp.getYValue() == 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 | |
System.out.println("Value: " + cp.getYValue()); | |
System.out.println("IsInSecondaryPlot: " + cp.isInSecondaryPlot()); | |
System.out.println(); |
控制台输出
请查看执行上述示例代码并使用示例 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