Free Support Forum - aspose.com

Hi...can u help me please

need to know how exactly we provide the backgradient color for a chart

Hi,


See a sample code below for your reference, in the example, we have set gradient color for the Chart’s plot area.

Sample code:


Workbook workbook = new Workbook();
//Set default font
Style style = workbook.DefaultStyle;
style.Font.Name = “Tahoma”;
workbook.DefaultStyle = style;
Worksheet sheet = workbook.Worksheets[0];
//Set the name of worksheet
sheet.Name = “Data”;
Cells cells = workbook.Worksheets[0].Cells;
//Put a value into a cell
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);

int sheetIndex = workbook.Worksheets.Add();
sheet = workbook.Worksheets[sheetIndex];
//Set the name of worksheet
sheet.Name = “Chart”;
//Create first chart
int chartIndex = 0;
chartIndex = sheet.Charts.Add(ChartType.Doughnut,1,1,25,10);
Chart chart = sheet.Charts[chartIndex];
//Set properties of chart
chart.PlotArea.Area.ForegroundColor = Color.Coral;
chart.PlotArea.Area.FillFormat.SetTwoColorGradient(Color.Yellow,Color.White,GradientStyleType.Vertical,2);
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,Data!B4,Data!B6,Data!B8”, true);
chart.NSeries.CategoryData = “Data!A2,Data!A4,Data!A6,Data!A8”;
chart.NSeries.IsColorVaried = true;
//Set the ChartArea
ChartArea chartarea = chart.ChartArea;
chartarea.Area.Formatting = FormattingType.Custom;
chartarea.Area.FillFormat.Texture = TextureType.BlueTissuePaper;
chart.NSeries[0].DataLabels.IsPercentageShown = true;
chart.NSeries[0].DataLabels.IsValueShown = true;
chart.IsLegendShown = false;
//Save the excel file
workbook.Save(“d:\test\doughnut_chart1.xls”);

Also, see the document for your reference:
http://www.aspose.com/docs/display/cellsnet/Manipulating+Designer+Charts

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Please use the Style.SetTwoColorGradient() method for your needs. Please see the following code for your more help.

I have also attached the output file generated by this code for your reference.

C#


Workbook workbook = new Workbook();


Worksheet worksheet = workbook.Worksheets[0];


Cell cell = worksheet.Cells[“D4”];


Style style = cell.GetStyle();

style.SetTwoColorGradient(Color.Green, Color.Red, GradientStyleType.DiagonalDown, 1);


cell.SetStyle(style);



workbook.Save(“output.xlsx”);

Thank you for the solution…its working :slight_smile:

Hi,

Thanks for your posting and using Aspose.Cells.

We are glad that your issue is resolved with the above code. If you face any other issue, please feel free to post, we will be pleased to help you further.