Imposta l immagine come riempimento di sfondo nel grafico
Contents
[
Hide
]
Aspose.Cells per Python via .NET permette di impostare un gradiente, una trama, un motivo o un’immagine come effetti di riempimento per diversi oggetti, come l’area plot, l’area del grafico o la casella della legenda di un grafico. Questo documento mostra come aggiungere un’immagine come sfondo di un grafico.
Per ottenere questo, Aspose.Cells per Python via .NET fornisce la proprietà Chart.plot_area.area.fill_format.image_data. L’esempio di codice seguente dimostra l’uso della proprietà Chart.plot_area.area.fill_format.image_data per impostare un’immagine come riempimento di sfondo nel grafico.
Codice C# per impostare un’immagine come riempimento di sfondo nel grafico
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from aspose.cells import SheetType, Workbook | |
from aspose.cells.charts import ChartType, LegendPositionType | |
from aspose.pydrawing import Color | |
import bytearray | |
# 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 a new Workbook. | |
workbook = Workbook() | |
# Get the first worksheet. | |
sheet = workbook.worksheets[0] | |
# Set the name of worksheet | |
sheet.name = "Data" | |
# Get the cells collection in the sheet. | |
cells = workbook.worksheets[0].cells | |
# Put some values into a cells of the Data sheet. | |
cells.get("A1").put_value("Region") | |
cells.get("A2").put_value("France") | |
cells.get("A3").put_value("Germany") | |
cells.get("A4").put_value("England") | |
cells.get("A5").put_value("Sweden") | |
cells.get("A6").put_value("Italy") | |
cells.get("A7").put_value("Spain") | |
cells.get("A8").put_value("Portugal") | |
cells.get("B1").put_value("Sale") | |
cells.get("B2").put_value(70000) | |
cells.get("B3").put_value(55000) | |
cells.get("B4").put_value(30000) | |
cells.get("B5").put_value(40000) | |
cells.get("B6").put_value(35000) | |
cells.get("B7").put_value(32000) | |
cells.get("B8").put_value(10000) | |
# Add a chart sheet. | |
sheetIndex = workbook.worksheets.add(SheetType.CHART) | |
sheet = workbook.worksheets[sheetIndex] | |
# Set the name of worksheet | |
sheet.name = "Chart" | |
# Create chart | |
chartIndex = 0 | |
chartIndex = sheet.charts.add(ChartType.COLUMN, 1, 1, 25, 10) | |
chart = sheet.charts[chartIndex] | |
# Set some properties of chart plot area. | |
# To set a picture as fill format and make the border invisible. | |
fs = open(dataDir + "aspose.png", "rb") | |
data = bytearray(utils.filesize(fs)) | |
fs.readinto(data) | |
chart.plot_area.area.fill_format.image_data = data | |
chart.plot_area.border.is_visible = False | |
# Set properties of chart title | |
chart.title.text = "Sales By Region" | |
chart.title.font.color = Color.blue | |
chart.title.font.is_bold = True | |
chart.title.font.size = 12 | |
# Set properties of nseries | |
chart.n_series.add("Data!B2:B8", True) | |
chart.n_series.category_data = "Data!A2:A8" | |
chart.n_series.is_color_varied = True | |
# Set the Legend. | |
legend = chart.legend | |
legend.position = LegendPositionType.TOP | |
# Save the excel file | |
workbook.save(dataDir + "column_chart_out.xls") |