Gestisci assi dei grafici di Excel

Opzioni dell’asse

Aspose.Cells per Python via .NET consente anche di gestire gli assi del grafico a runtime, con oggetto Axis, puoi modificare tutte le opzioni di Axis come in Excel.

|todo:image_alt_text|

Gestisci gli assi X e Y

Nel grafico Excel, gli assi orizzontali e verticali sono i due assi più popolari da utilizzare.

Il seguente snippet di codice dimostra come impostare le opzioni degli assi 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")

Argomenti avanzati