Free Support Forum - aspose.com

Aspose.Cells : Backimage for Excel Charts

Dear,

We have a license for Aspose.Words and Aspose.Cells. 

 I'm looking for the functionality to add a backimage in an Excel Chart within Aspose.Cells. I can only find TextureType and Pattern fill options. However, we need to add the logo of the company.

Does the possibility exist to add such an image like in Excel (Plotarea / Fill effects / 4th tab = image), or do I need to use either the Texture of Pattern functionlity? Can you show me how I can do this (example).

Thanks in advance for your response.


This message was posted using Aspose.Live 2 Forum

Hi,

Thanks for your inquiry.

Well, setting background image is not supported at the moment. But, you may set Gradient, Texture or Pattern attributes as a fill format for the plot area in your chart. See the following example for reference. In the example I have applied Texture attributes for the plot area and legend’s fill formats.

Sample code:
//Create a new Workbook.
Workbook workbook = new Workbook();
//Get the first worksheet.
Worksheet sheet = workbook.Worksheets[0];
//Set the name of worksheet
sheet.Name = “Data”;
//Get the cells collection in the sheet.
Cells cells = workbook.Worksheets[0].Cells;

//Put some values into a cells of the Data sheet.
cells[“A1”].PutValue(“Region”);
cells[“A2”].PutValue(“France”);
cells[“A3”].PutValue(“Germany”);
cells[“A4”].PutValue(“England”);
cells[“A5”].PutValue(“Sweden”);
cells[“A6”].PutValue(“Italy”);
cells[“A7”].PutValue(“Spain”);
cells[“A8”].PutValue(“Portugal”);
cells[“B1”].PutValue(“Sale”);
cells[“B2”].PutValue(70000);
cells[“B3”].PutValue(55000);
cells[“B4”].PutValue(30000);
cells[“B5”].PutValue(40000);
cells[“B6”].PutValue(35000);
cells[“B7”].PutValue(32000);
cells[“B8”].PutValue(10000);

//Add a chart sheet.
int sheetIndex = workbook.Worksheets.Add(SheetType.Chart);
sheet = workbook.Worksheets[sheetIndex];
//Set the name of worksheet
sheet.Name = “Chart”;
//Create chart
int chartIndex = 0;
chartIndex = sheet.Charts.Add(ChartType.Pie, 1, 1, 25, 10);
Chart chart = sheet.Charts[chartIndex];
//Set some properties of chart plot area.
//to set the texture fill color and make the border invisible.
chart.PlotArea.Area.Formatting = FormattingType.Custom;
chart.PlotArea.Area.FillFormat.Texture = TextureType.BlueTissuePaper;
chart.PlotArea.Border.IsVisible = false;

//Set properties of chart title
chart.Title.Text = “Sales By Region”;
chart.Title.TextFont.Color = Color.Blue;
chart.Title.TextFont.IsBold = true;
chart.Title.TextFont.Size = 12;

//Set properties of nseries
chart.NSeries.Add(“Data!B2:B8”, true);
chart.NSeries.CategoryData = “Data!A2:A8”;
chart.NSeries.IsColorVaried = true;

//Set the DataLabels in the chart
DataLabels datalabels;
for (int i = 0; i < chart.NSeries.Count; i++)
{
datalabels = chart.NSeries[i].DataLabels;
datalabels.Postion = LabelPositionType.InsideBase;
datalabels.IsCategoryNameShown = true;
datalabels.IsValueShown = true;
datalabels.IsPercentageShown = false;
datalabels.IsLegendKeyShown = false;

}

//Set the Legend.
Legend legend = chart.Legend;
legend.Position = LegendPositionType.Left;
legend.Height = 100;
legend.Width = 130;
legend.Y = 1500;
legend.TextFont.IsBold = true;
legend.Border.Color = Color.Blue;
legend.Area.Formatting = FormattingType.Custom;
//Set FillFormat.
Aspose.Cells.FillFormat fillformat = legend.Area.FillFormat;
fillformat.Texture = TextureType.Bouquet;
//Save the excel file
workbook.Save(“f:\test\newtest_pie_chart.xls”, FileFormatType.Excel2003);


Also, your feature request has been logged into our issue tracking system (internal) with an issue id: CELLSNET-11502. We will check and analyze the feature for its feasibility if we can support it. We will update you if there is some work done on it.

Thank you.

Hi,

Please try the attached version v4.8.0.14, we have supported to set a picture as the background image in a chart.

Here is the sample code:

Workbook workbook = new Workbook();
Aspose.Cells.Cells cells = workbook.Worksheets[0].Cells;
cells[“A1”].PutValue(1);
cells[“A2”].PutValue(2);
FileStream fs = File.OpenRead(@“F:\test\school.jpg”);
byte[] data = new byte[fs.Length];
fs.Read(data, 0, data.Length);
Charts charts = workbook.Worksheets[0].Charts;
charts.Add(ChartType.Column, 0, 0, 10, 5);
charts[0].NSeries.Add(“A1:A2”, true);
charts[0].PlotArea.Area.FillFormat.ImageData = data;

workbook.Save(@“F:\test\dest.xls”);

Thank you.

Hi,

works like a charm. The easiness - is this a word? - and speed of the solution was astounding.

Thanks very very much !