在计算图表后读取轴标签

可能的使用场景

您可以在计算图表数值后,使用Chart.calculate()方法读取您的图表的轴标签。请为此目的使用Axis.getAxisTexts()方法,它将返回轴标签的列表。

计算图表后读取轴标签

请查看以下示例代码,加载 示例 Excel文件,读取第一个工作表中图表的类别轴标签。然后在控制台上打印轴标签的值。请参考下面给出的示例代码的控制台输出。

示例代码

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

控制台输出

 Category Axis Labels:

\---------------------

Iran

China

USA

Brazil

England