How to set the background color for Excel Chart in C#

As a powerful Excel library, Spire.XLS supports to work with many kinds of charts and it also supports to set the performance for the chart. We have already shown you how to fill the excel chart with background image to make the chart more attractive. This article will show you how to fill the excel chart with background color in C#.

Please check the original Excel chart without any background color:

How to set the background color for Excel Chart in C#

Code Snippet for Inserting Background color:

Step 1: Create a new workbook and load from file.

Workbook workbook = new Workbook();
workbook.LoadFromFile("sample.xlsx");

Step 2: Get the first worksheet from workbook and then get the first chart from the worksheet.

Worksheet ws = workbook.Worksheets[0];
Chart chart = ws.Charts[0];

Step 3: Set the property to ForeGroundColor for PlotArea to fill the background color for the chart.

chart.PlotArea.ForeGroundColor = System.Drawing.Color.LightYellow;

Step 4: Save the document to file.

workbook.SaveToFile("result.xlsx",ExcelVersion.Version2010);

Effective screenshot after fill the background color for Excel chart:

How to set the background color for Excel Chart in C#

Full codes:

using Spire.Xls;
namespace SetBackgroundColor
{
    class Program
    {

        static void Main(string[] args)
        {
            Workbook workbook = new Workbook();
            workbook.LoadFromFile("sample.xlsx");

            Worksheet ws = workbook.Worksheets[0];
            Chart chart = ws.Charts[0];

            chart.PlotArea.ForeGroundColor = System.Drawing.Color.LightYellow;

            workbook.SaveToFile("result.xlsx", ExcelVersion.Version2010);
        }

    }
}