确定图表中存在哪个轴
Contents
[
Hide
]
有时,用户需要知道图表中是否存在特定轴。例如,他想知道图表中是否存在次要值轴。像饼图、圆环图等一些图表不包含轴。
Aspose.Cells提供了Chart.hasAxis(int axisType, boolean isPrimary)方法来判断图表是否具有特定的轴。
##确定图表中存在哪个轴
以下屏幕截图显示了一个图表,只包含主类别和值轴。它不包含任何次要类别和值轴。
以下示例代码演示了如何使用 Chart.hasAxis(int axisType, boolean isPrimary) 确定示例图表是否具有主类别和辅助类别以及数值轴。代码的控制台输出如下,显示主类别和数值轴的值为true,辅助类别和数值轴的值为false。
用于确定图表中存在哪些轴的Java代码
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.getDataDir(DetermineWhichAxisExistsInChart.class); | |
// Create workbook object | |
Workbook workbook = new Workbook(dataDir + "source.xlsx"); | |
// Access the first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Access the chart | |
Chart chart = worksheet.getCharts().get(0); | |
// Determine which axis exists in chart | |
boolean ret = chart.hasAxis(AxisType.CATEGORY, true); | |
System.out.println("Has Primary Category Axis: " + ret); | |
ret = chart.hasAxis(AxisType.CATEGORY, false); | |
System.out.println("Has Secondary Category Axis: " + ret); | |
ret = chart.hasAxis(AxisType.VALUE, true); | |
System.out.println("Has Primary Value Axis: " + ret); | |
ret = chart.hasAxis(AxisType.VALUE, false); | |
System.out.println("Has Secondary Value Axis: " + ret); |
样本代码生成的控制台输出
这是上述样本代码的控制台输出。
Has Primary Category Axis: true
Has Secondary Category Axis: false
Has Primary Value Axis: true
Has Secondary Value Axis: false