Gestion des Axes des Graphiques Excel

Options d’Axe

Aspose.Cells pour Python via .NET permet également de gérer les axes du graphique en temps réel, avec l’objet Axis, vous pouvez changer toutes les options de l’axe comme dans Excel.

|todo:image_alt_text|

Gérer les axes des X et Y

Dans un graphique Excel, les axes horizontal et vertical sont les deux axes les plus populaires à utiliser.

L’extrait de code suivant illustre comment définir les options des axes des X et 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")

Sujets avancés