Read Axis Labels after Calculating the Chart
Possible Usage Scenarios
You can read axis labels of your chart after calculating its values using the Chart.calculate() method. Please use the Axis.getAxisTexts() method for this purpose that will return the list of axis labels.
Read Axis Labels after Calculating the Chart
Please see the following sample code that loads the sample Excel file and reads the category axis labels of the chart in the first worksheet. It then prints the values of the axis labels on the console. Please see the console output of the sample code given below for a reference.
Sample Code
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
//Load the Excel file containing chart | |
Workbook wb = new Workbook("64716829.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access the chart | |
Chart ch = ws.getCharts().get(0); | |
//Calculate the chart | |
ch.calculate(); | |
//Read axis labels of category axis | |
String[] lstLabels = ch.getCategoryAxis().getAxisTexts(); | |
//Print axis labels on console | |
System.out.println("Category Axis Labels: "); | |
System.out.println("---------------------"); | |
//Iterate axis labels and print them one by one | |
for(int i=0; i<lstLabels.length; i++) | |
{ | |
System.out.println(lstLabels[i]); | |
} |
Console Output
Category Axis Labels:
\---------------------
Iran
China
USA
Brazil
England