Chart Plot Area in Excel document

26 Aug 20248 minutes to read

The plot area refers to the region that represents the plotted data in a chart. Using XlsIO, you can customize the plot area in the chart.

Formatting

Border

The following code snippet illustrates how to format the border of the plot area.

//Format Plot Area
IChartFrameFormat chartPlotArea = chart.PlotArea;

//Set the border
chartPlotArea.Border.LinePattern = ExcelChartLinePattern.Solid;
chartPlotArea.Border.LineColor = Color.Blue;
chartPlotArea.Border.LineWeight = ExcelChartLineWeight.Hairline;
//Format Plot Area
IChartFrameFormat chartPlotArea = chart.PlotArea;

//Set the border
chartPlotArea.Border.LinePattern = ExcelChartLinePattern.Solid;
chartPlotArea.Border.LineColor = Color.Blue;
chartPlotArea.Border.LineWeight = ExcelChartLineWeight.Hairline;
'Format Plot Area
IChartFrameFormat chartPlotArea = chart.PlotArea

'Set the border
chartPlotArea.Border.LinePattern = ExcelChartLinePattern.Solid
chartPlotArea.Border.LineColor = Color.Blue
chartPlotArea.Border.LineWeight = ExcelChartLineWeight.Hairline

Color

The following code snippet illustrates how to format the color of the plot area.

//Set the color
chartPlotArea.Fill.FillType = ExcelFillType.Gradient;
chartPlotArea.Fill.GradientColorType = ExcelGradientColor.TwoColor;
chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234);
chartPlotArea.Fill.ForeColor = Color.White;
//Set the color
chartPlotArea.Fill.FillType = ExcelFillType.Gradient;
chartPlotArea.Fill.GradientColorType = ExcelGradientColor.TwoColor;
chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234);
chartPlotArea.Fill.ForeColor = Color.White;
'Set the color
chartPlotArea.Fill.FillType = ExcelFillType.Gradient
chartPlotArea.Fill.GradientColorType = ExcelGradientColor.TwoColor
chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234)
chartPlotArea.Fill.ForeColor = Color.White

Transparency

The following code snippet illustrates how to apply transparency in the plot area.

//Set the transparency
chartPlotArea.Fill.Transparency = 0.5;
//Set the transparency 
chartPlotArea.Fill.Transparency = 0.5;
'Set the transparency 
chartPlotArea.Fill.Transparency = 0.5

NOTE

Transparency is only applicable when FillType is set as SolidColor. Color-shaded fill is represented as a floating-point value ranging from 0.0 (Clear) to 1.0 (Opaque).

Set position

The following code snippet illustrates how to set the position of the plot area.

//Set the position
chartPlotArea.Layout.Left = 5;
//Set the position
chartPlotArea.Layout.Left = 5;
'Set the position 
chartPlotArea.Layout.Left = 5;

The complete code snippet illustrating the above options is shown below.

using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Xlsx;
  FileStream inputStream = new FileStream("../../../Data/InputTemplate.xlsx", FileMode.Open, FileAccess.Read);
  IWorkbook workbook = application.Workbooks.Open(inputStream);
  IWorksheet sheet = workbook.Worksheets[0];
  IChartShape chart = sheet.Charts[0];

  //Format Plot Area
  IChartFrameFormat chartPlotArea = chart.PlotArea;

  //Set the border
  chartPlotArea.Border.LinePattern = ExcelChartLinePattern.Solid;
  chartPlotArea.Border.LineColor = Color.Blue;
  chartPlotArea.Border.LineWeight = ExcelChartLineWeight.Hairline;

  //Set the color
  chartPlotArea.Fill.FillType = ExcelFillType.Gradient;
  chartPlotArea.Fill.GradientColorType = ExcelGradientColor.TwoColor;
  chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234);
  chartPlotArea.Fill.ForeColor = Color.White;

  //Set the position
  chartPlotArea.Layout.Left = 5;

  //Saving the workbook as stream
  FileStream outputStream = new FileStream("Output.xlsx", FileMode.Create, FileAccess.ReadWrite);
  workbook.SaveAs(outputStream);

  //Dispose streams
  outputStream.Dispose();
  inputStream.Dispose();
}
using (ExcelEngine excelEngine = new ExcelEngine())
{
  IApplication application = excelEngine.Excel;
  application.DefaultVersion = ExcelVersion.Xlsx;
  IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");
  IWorksheet sheet = workbook.Worksheets[0];
  IChartShape chart = sheet.Charts[0];

  //Format Plot Area
  IChartFrameFormat chartPlotArea = chart.PlotArea;

  //Set the border
  chartPlotArea.Border.LinePattern = ExcelChartLinePattern.Solid;
  chartPlotArea.Border.LineColor = Color.Blue;
  chartPlotArea.Border.LineWeight = ExcelChartLineWeight.Hairline;

  //Set the color
  chartPlotArea.Fill.FillType = ExcelFillType.Gradient;
  chartPlotArea.Fill.GradientColorType = ExcelGradientColor.TwoColor;
  chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234);
  chartPlotArea.Fill.ForeColor = Color.White;

  //Set the position
  chartPlotArea.Layout.Left = 5;

  //Saving the workbook
  workbook.SaveAs("Output.xlsx");
}
Using excelEngine As ExcelEngine = New ExcelEngine()
  Dim application As IApplication = excelEngine.Excel
  application.DefaultVersion = ExcelVersion.Xlsx
  Dim workbook As IWorkbook = application.Workbooks.Open("InputTemplate.xlsx")
  Dim sheet As IWorksheet = workbook.Worksheets(0)
  Dim chart As IChartShape = sheet.Charts(0)

  'Format Plot Area
  Dim chartPlotArea As IChartFrameFormat = chart.PlotArea

  'Set the border
  chartPlotArea.Border.LinePattern = ExcelChartLinePattern.Solid
  chartPlotArea.Border.LineColor = Color.Blue
  chartPlotArea.Border.LineWeight = ExcelChartLineWeight.Hairline

  'Set the color
  chartPlotArea.Fill.FillType = ExcelFillType.Gradient
  chartPlotArea.Fill.GradientColorType = ExcelGradientColor.TwoColor
  chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234)
  chartPlotArea.Fill.ForeColor = Color.White

  'Set the position
  chartPlotArea.Layout.Left = 5

  'Saving the workbook
  workbook.SaveAs("Output.xlsx")
End Using

A complete working example for the chart plot area in C# is present on this GitHub page.