在计算图表后读取轴标签

可能的使用场景

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

计算图表后读取轴标签

请参阅以下示例代码,加载[sample Excel file](ReadAxisLabels.xlsx)并读取第一个工作表中图表的类别轴标签。然后在控制台上打印轴标签的值。请参阅下面的示例代码的控制台输出进行参考。

示例代码

from aspose.cells import Workbook
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Load the Excel file containing chart
wb = Workbook("ReadAxisLabels.xlsx")
# Access first worksheet
ws = wb.worksheets[0]
# Access the chart
ch = ws.charts[0]
# Calculate the chart
ch.calculate()
# Read axis labels of category axis
lstLabels = ch.category_axis.get_axis_texts()
# Print axis labels on console
print("Category Axis Labels: ")
print("---------------------")
# Iterate axis labels and print them one by one
for i in range(len(lstLabels)):
print(lstLabels[i])

控制台输出

 Category Axis Labels:

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

Iran

China

USA

Brazil

England