Chart Plot Area in an Excel document
24 Jul 20267 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.
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.HairlineColor
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.WhiteTransparency
The following code snippet illustrates how to apply transparency to the plot area. This snippet assumes chartPlotArea is already initialized from the Border or Color example.
//Set the transparency
chartPlotArea.Fill.Transparency = 0.5;//Set the transparency
chartPlotArea.Fill.Transparency = 0.5;'Set the transparency
chartPlotArea.Fill.Transparency = 0.5NOTE
Transparency is only applicable when FillType is set as SolidColor. The value is a floating-point number ranging from 0.0 (Clear) to 1.0 (Opaque).
Set the Position
The following code snippet illustrates how to set the position of the plot area. This snippet assumes chartPlotArea is already initialized from the Border or Color example.
//Set the position
chartPlotArea.Layout.Left = 5;//Set the position
chartPlotArea.Layout.Left = 5;'Set the position
chartPlotArea.Layout.Left = 5The complete code snippet illustrating the above options is shown below.
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
IWorkbook workbook = application.Workbooks.Open(Path.GetFullPath(@"Data/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(Path.GetFullPath("Output/Output.xlsx"));
}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 UsingA complete working example for the chart plot area in C# is present on this GitHub page.