确定图表中存在哪个轴
Contents
[
Hide
]
有时,用户需要知道图表中是否存在特定轴。例如,他想知道图表中是否存在次要值轴。一些图表,如 Pie、PieExploded、PiePie、PieBar、Pie3D、Pie3DExploded、Doughnut、DoughnutExploded 等没有轴。
Aspose.Cells提供Chart.hasAxis(int axisType, boolean isPrimary) 方法来确定图表是否具有特定轴。
确定图表中存在哪个轴
以下屏幕截图显示了一个只有主类别和值轴的图表。它没有任何次要类别和价值轴。
下面的示例代码演示了使用[Chart.hasAxis(int axisType, boolean isPrimary)](https://reference.aspose.com/cells/java/com.aspose.cells/chart#hasAxis(int,%20boolean)以确定示例图表是否具有主要和次要类别以及值轴。代码的控制台输出如下所示,其中对主要类别和价值轴显示 true,对次要类别和价值轴显示 false。
Java 确定图表中存在哪个轴的代码
This file contains hidden or 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