Customize the Chart Area in PowerPoint
28 Jul 20269 minutes to read
Chart area refers to the space that contains the chart or graph you’ve inserted into a document. It includes the entire chart and all its elements, such as data points, labels, axes, and the plot area. Using Presentation, you can customize the chart area in the chart.
NOTE
For prerequisites (installing the NuGet packages, required namespaces, and creating a chart), refer to the Getting Started and NuGet Packages Required documentation.
Customize the Border
The following code snippet illustrates how to modify the border of the chart area.
//Format the chart area.
IOfficeChartFrameFormat chartArea = chart.ChartArea;
//Set border line pattern, color, and line weight.
chartArea.Border.LinePattern = OfficeChartLinePattern.Solid;
chartArea.Border.LineColor = Syncfusion.Drawing.Color.Blue;
chartArea.Border.LineWeight = OfficeChartLineWeight.Hairline;//Format the chart area.
IOfficeChartFrameFormat chartArea = chart.ChartArea;
//Set border line pattern, color, and line weight.
chartArea.Border.LinePattern = OfficeChartLinePattern.Solid;
chartArea.Border.LineColor = Color.Blue;
chartArea.Border.LineWeight = OfficeChartLineWeight.Hairline;' Format the chart area.
Dim chartArea As IOfficeChartFrameFormat = chart.ChartArea
' Set border line pattern, color, and line weight.
chartArea.Border.LinePattern = OfficeChartLinePattern.Solid
chartArea.Border.LineColor = Color.Blue
chartArea.Border.LineWeight = OfficeChartLineWeight.HairlineNOTE
For more information on the available
OfficeChartLinePatternandOfficeChartLineWeightenum values, see the API reference.
Customize the Fill
The following code snippet illustrates how to apply a gradient fill to the chart area.
//Format the chart area.
IOfficeChartFrameFormat chartArea = chart.ChartArea;
//Set fill type and fill colors.
chartArea.Fill.FillType = OfficeFillType.Gradient;
chartArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
chartArea.Fill.BackColor = Syncfusion.Drawing.Color.FromArgb(205, 217, 234);
chartArea.Fill.ForeColor = Syncfusion.Drawing.Color.White;//Format the chart area.
IOfficeChartFrameFormat chartArea = chart.ChartArea;
//Set fill type and fill colors.
chartArea.Fill.FillType = OfficeFillType.Gradient;
chartArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
chartArea.Fill.BackColor = Color.FromArgb(205, 217, 234);
chartArea.Fill.ForeColor = Color.White;' Format the chart area.
Dim chartArea As IOfficeChartFrameFormat = chart.ChartArea
' Set fill type and fill colors.
chartArea.Fill.FillType = OfficeFillType.Gradient
chartArea.Fill.GradientColorType = OfficeGradientColor.TwoColor
chartArea.Fill.BackColor = Color.FromArgb(205, 217, 234)
chartArea.Fill.ForeColor = Color.WhiteThe complete code snippet illustrating the above options is shown below.
//Open an existing PowerPoint Presentation.
using (IPresentation pptxDoc = Presentation.Open("Data/Template.pptx"))
{
//Gets the first slide.
ISlide slide = pptxDoc.Slides[0];
//Gets the chart in the slide.
IPresentationChart chart = slide.Shapes[0] as IPresentationChart;
//Format the chart area.
IOfficeChartFrameFormat chartArea = chart.ChartArea;
//Set border line pattern, color, and line weight.
chartArea.Border.LinePattern = OfficeChartLinePattern.Solid;
chartArea.Border.LineColor = Syncfusion.Drawing.Color.Blue;
chartArea.Border.LineWeight = OfficeChartLineWeight.Hairline;
//Set fill type and fill colors.
chartArea.Fill.FillType = OfficeFillType.Gradient;
chartArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
chartArea.Fill.BackColor = Syncfusion.Drawing.Color.FromArgb(205, 217, 234);
chartArea.Fill.ForeColor = Syncfusion.Drawing.Color.White;
//Save the PowerPoint Presentation.
pptxDoc.Save("Result.pptx");
}//Open an existing PowerPoint Presentation.
using (IPresentation pptxDoc = Presentation.Open("Template.pptx"))
{
//Gets the first slide.
ISlide slide = pptxDoc.Slides[0];
//Gets the chart in the slide.
IPresentationChart chart = slide.Shapes[0] as IPresentationChart;
//Format the chart area.
IOfficeChartFrameFormat chartArea = chart.ChartArea;
//Set border line pattern, color, and line weight.
chartArea.Border.LinePattern = OfficeChartLinePattern.Solid;
chartArea.Border.LineColor = Syncfusion.Drawing.Color.Blue;
chartArea.Border.LineWeight = OfficeChartLineWeight.Hairline;
//Set fill type and fill colors.
chartArea.Fill.FillType = OfficeFillType.Gradient;
chartArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
chartArea.Fill.BackColor = Syncfusion.Drawing.Color.FromArgb(205, 217, 234);
chartArea.Fill.ForeColor = Syncfusion.Drawing.Color.White;
//Save the PowerPoint Presentation.
pptxDoc.Save("Result.pptx");
}' Load an existing PowerPoint presentation.
Using pptxDoc As IPresentation = Presentation.Open("Template.pptx")
' Get the first slide.
Dim slide As ISlide = pptxDoc.Slides(0)
' Get the chart from the slide.
Dim chart As IPresentationChart = TryCast(slide.Shapes(0), IPresentationChart)
' Format the chart area.
Dim chartArea As IOfficeChartFrameFormat = chart.ChartArea
' Set border line pattern, color, and line weight.
chartArea.Border.LinePattern = OfficeChartLinePattern.Solid
chartArea.Border.LineColor = Syncfusion.Drawing.Color.Blue
chartArea.Border.LineWeight = OfficeChartLineWeight.Hairline
' Set fill type and fill colors.
chartArea.Fill.FillType = OfficeFillType.Gradient
chartArea.Fill.GradientColorType = OfficeGradientColor.TwoColor
chartArea.Fill.BackColor = Syncfusion.Drawing.Color.FromArgb(205, 217, 234)
chartArea.Fill.ForeColor = Syncfusion.Drawing.Color.White
' Save the PowerPoint presentation.
pptxDoc.Save("Result.pptx")
End UsingYou can download a complete working sample from GitHub.
Add Image in Chart Area
The following code snippet illustrates how to fill the image in chart area.
//Append image in chart area.
FileStream imageStream = new FileStream("Data/Image.png", FileMode.Open, FileAccess.Read);
Image image = Image.FromStream(imageStream);
chartArea.Fill.UserPicture(image, "image");//Append image in chart area.
chartArea.Fill.UserPicture("Image.png");' Append an image to the chart area.
chartArea.Fill.UserPicture("Image.png")Set the Transparency level
The following code snippet illustrates how to make transparency in chart area.
// Set the transparency of the chart area.
chartArea.Fill.Transparency = 0.5;// Set the transparency of the chart area.
chartArea.Fill.Transparency = 0.5;' Set the transparency of the chart area.
chartArea.Fill.Transparency = 0.5NOTE
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).