Manage Axes of Excel Charts

Axis Options

Aspose.Cells for Python via .NET also allows to manage chart’s axes at runtime,with Axis object, you can change all options of Axis as done in Excel.

|todo:image_alt_text|

Manage X and Y Axes

In Excel chart, horizonal and vertical axes are the two most popular axes to use.

The following code snippet demonstrates how to set the options of X and Y axes .

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")

Advance topics