Determine which Axis exists in the Chart

Determine which Axis exists in the Chart

The following screenshot shows a chart that has only the Primary Category and Value Axis. It does not have any Secondary Category and Value Axis.

todo:image_alt_text

The following sample code demonstrates the use of Chart.hasAxis(int axisType, boolean isPrimary) to determine if the sample chart has Primary and Secondary Category and Value Axis. The console output of the code has been shown below which displays true for Primary Category and Value Axis and false for Secondary Category and Value Axis.

Java code to determine which axis exist in the chart

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

Console output generated by the sample code

Here is the Console Output of the above Sample Code.

Has Primary Category Axis: true

Has Secondary Category Axis: false

Has Primary Value Axis: true

Has Secondary Value Axis: false