Gestionar títulos de los gráficos de Excel

Opciones de Títulos

Aspose.Cells para Python via .NET también permite gestionar los títulos del gráfico en tiempo de ejecución; con el objeto Título, puedes cambiar el texto, la fuente y el formato de relleno de los títulos.

|todo:image_alt_text|

Configuración de los Títulos de Gráficos o Ejes

Puedes usar Microsoft Excel para configurar los títulos de un gráfico y sus ejes en un entorno WYSIWYG. Aspose.Cells para Python via .NET también permite a los desarrolladores establecer los títulos de un gráfico y sus ejes en tiempo de ejecución. Todos los gráficos y sus ejes contienen una propiedad título que puede usarse para establecer sus títulos, como se muestra en el ejemplo a continuación.

El siguiente fragmento de código demuestra cómo establecer títulos en gráficos y ejes.

from aspose.cells import Workbook
from aspose.cells.charts import ChartType
from aspose.cells.drawing import GradientStyleType
from aspose.pydrawing import Color
from os import os, path
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
dataDir = RunExamples.GetDataDir(".")
# Create directory if it is not already present.
IsExists = path.isdir(dataDir)
if notIsExists:
os.makedirs(dataDir)
# 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(50)
worksheet.cells.get("A2").put_value(100)
worksheet.cells.get("A3").put_value(150)
worksheet.cells.get("B1").put_value(60)
worksheet.cells.get("B2").put_value(32)
worksheet.cells.get("B3").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.n_series.add("A1:B3", True)
# Setting the foreground color of the plot area
chart.plot_area.area.foreground_color = Color.blue
# Setting the foreground color of the chart area
chart.chart_area.area.foreground_color = Color.yellow
# Setting the foreground color of the 1st SeriesCollection area
chart.n_series[0].area.foreground_color = Color.red
# Setting the foreground color of the area of the 1st SeriesCollection point
chart.n_series[0].points[0].area.foreground_color = Color.cyan
# Filling the area of the 2nd SeriesCollection with a gradient
chart.n_series[1].area.fill_format.set_one_color_gradient(Color.lime, 1, GradientStyleType.HORIZONTAL, 1)
# Setting the title of a chart
chart.title.text = "Title"
# Setting the font color of the chart title to blue
chart.title.font.color = Color.blue
# Setting the title of category axis of the chart
chart.category_axis.title.text = "Category"
# Setting the title of value axis of the chart
chart.value_axis.title.text = "Value"
# Saving the Excel file
workbook.save(dataDir + "book1.out.xls")

Temas avanzados