确定图表中存在哪个轴

##确定图表中存在哪个轴

以下屏幕截图显示了一个图表,只包含主类别和值轴。它不包含任何次要类别和值轴。

todo:image_alt_text

以下示例代码演示了如何使用 Chart.hasAxis(int axisType, boolean isPrimary) 确定示例图表是否具有主类别和辅助类别以及数值轴。代码的控制台输出如下,显示主类别和数值轴的值为true,辅助类别和数值轴的值为false。

用于确定图表中存在哪些轴的Java代码

// 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