在图表中设置图片作为背景填充

Contents
[ ]

要实现此功能,Aspose.Cells for Python via .NET 提供了 Chart.plot_area.area.fill_format.image_data 属性。以下示例演示如何使用 Chart.plot_area.area.fill_format.image_data 属性设置图片作为图表背景填充。

##将图片设置为图表的背景填充的C#代码

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