管理Excel图表的轴
Contents
[
Hide
]
在Excel图表中,有3种类型的轴:
- 水平(类别)轴:X轴
- 垂直(值)轴:Y轴
- 深度(系列)轴:Z轴
轴选项
Aspose.Cells for Python via .NET还允许在运行时管理图表的坐标轴,使用Axis对象,你可以像在Excel中一样更改Axis的所有选项。
||
管理X和Y轴
在Excel图表中,水平和垂直轴是最常用的两种轴。
以下代码片段演示了如何设置X和Y轴的选项。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import Workbook | |
from aspose.cells.charts import ChartType | |
# Instantiating a Workbook object | |
workbook = Workbook() | |
# Adding a new worksheet to the Workbook object | |
sheetIndex = workbook.worksheets.add() | |
# Obtaining the reference of the newly added worksheet by passing its sheet index | |
worksheet = workbook.worksheets[sheetIndex] | |
# Adding sample values to cells | |
worksheet.cells.get("A1").put_value("Series1") | |
worksheet.cells.get("A2").put_value(50) | |
worksheet.cells.get("A3").put_value(100) | |
worksheet.cells.get("A4").put_value(150) | |
worksheet.cells.get("B1").put_value("Series2") | |
worksheet.cells.get("B2").put_value(60) | |
worksheet.cells.get("B3").put_value(32) | |
worksheet.cells.get("B4").put_value(50) | |
# Adding a chart to the worksheet | |
chartIndex = worksheet.charts.add(ChartType.COLUMN, 5, 0, 15, 5) | |
# Accessing the instance of the newly added chart | |
chart = worksheet.charts[chartIndex] | |
# Adding SeriesCollection (chart data source) to the chart ranging from "A1" cell to "B3" | |
chart.set_chart_data_range("A1:B4", True) | |
# hiding X axis | |
chart.category_axis.is_visible = False | |
# Setting max value of Y axis. | |
chart.value_axis.max_value = 200 | |
# Setting major unit. | |
chart.value_axis.major_unit = 50.0 | |
# Save the file | |
workbook.save("chart_axes.xlsx") |