Gestionar ejes de gráficos de Excel
En los gráficos de Excel, hay 3 tipos de ejes:
- Eje Horizontal (Categoría): Eje X
- Eje Vertical (Valor): Eje Y
- Eje de Profundidad (Serie): Eje Z
Opciones del Eje
Aspose.Cells para Python via .NET también permite gestionar los ejes del gráfico en tiempo de ejecución, con el objeto Axis, puedes cambiar todas las opciones del Eje como se hace en Excel.
||
Administrar Ejes X e Y
En el gráfico de Excel, los ejes horizontal y vertical son los dos ejes más populares para usar.
El siguiente fragmento de código muestra cómo configurar las opciones de los ejes X e Y.
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") |