Customize Chart Plot Area

30 Aug 202410 minutes to read

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

Customization of Border

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

NOTE

Refer to the appropriate tabs in the code snippets section: C# [Cross-platform] for ASP.NET Core, Blazor, Xamarin, UWP, .NET MAUI, and WinUI; C# [Windows-specific] for WinForms and WPF; VB.NET [Windows-specific] for VB.NET applications.

//Format the plot area.
IOfficeChartFrameFormat chartPlotArea = chart.PlotArea;
//Plot area border settings - line pattern, color, weight.
chartPlotArea.Border.LinePattern = OfficeChartLinePattern.Solid;
chartPlotArea.Border.LineColor = Syncfusion.Drawing.Color.Blue;
chartPlotArea.Border.LineWeight = OfficeChartLineWeight.Hairline;
//Format the plot area.
IOfficeChartFrameFormat chartPlotArea = chart.PlotArea;
//Plot area border settings - line pattern, color, weight.
chartPlotArea.Border.LinePattern = OfficeChartLinePattern.Solid;
chartPlotArea.Border.LineColor = Color.Blue;
chartPlotArea.Border.LineWeight = OfficeChartLineWeight.Hairline;
' Format the plot area.
Dim chartPlotArea As IOfficeChartFrameFormat = chart.PlotArea
' Plot area border settings - line pattern, color, weight.
chartPlotArea.Border.LinePattern = OfficeChartLinePattern.Solid
chartPlotArea.Border.LineColor = Color.Blue
chartPlotArea.Border.LineWeight = OfficeChartLineWeight.Hairline

Customization of Color

The following code snippet illustrates how to fill the color in plot area.

//Set fill type and color.
 chartPlotArea.Fill.FillType = OfficeFillType.Gradient;
 chartPlotArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
 chartPlotArea.Fill.BackColor = Syncfusion.Drawing.Color.FromArgb(205, 217, 234);
 chartPlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.White;
//Set fill type and color.
 chartPlotArea.Fill.FillType = OfficeFillType.Gradient;
 chartPlotArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
 chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234);
 chartPlotArea.Fill.ForeColor = Color.White;
' Set fill type and color.
 chartPlotArea.Fill.FillType = OfficeFillType.Gradient
 chartPlotArea.Fill.GradientColorType = OfficeGradientColor.TwoColor
 chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234)
 chartPlotArea.Fill.ForeColor = Color.White

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

FileStream fileStreamPath = new FileStream("Data/Template.docx", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
//Opens an existing document from file system through constructor of WordDocument class.
using (WordDocument document = new WordDocument(fileStreamPath, FormatType.Docx))
{
    //Get the paragraph.
    WParagraph paragraph = document.LastParagraph;
    //Get the chart entity.
    WChart chart = paragraph.ChildEntities[0] as WChart;
    //Modify the chart height and width.
    chart.Height = 300;
    chart.Width = 500;

    //Plot Area.
    IOfficeChartFrameFormat chartPlotArea = chart.PlotArea;

    //Plot area border settings - line pattern, color, weight.
    chartPlotArea.Border.LinePattern = OfficeChartLinePattern.Solid;
    chartPlotArea.Border.LineColor = Syncfusion.Drawing.Color.Blue;
    chartPlotArea.Border.LineWeight = OfficeChartLineWeight.Hairline;

    //Set fill type and color.
    chartPlotArea.Fill.FillType = OfficeFillType.Gradient;
    chartPlotArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
    chartPlotArea.Fill.BackColor = Syncfusion.Drawing.Color.FromArgb(205, 217, 234);
    chartPlotArea.Fill.ForeColor = Syncfusion.Drawing.Color.White;

    using (FileStream outputStream = new FileStream("Sample.docx", FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
    {
        //Save the Word file.
        document.Save(outputStream, FormatType.Docx);
    }
}
using (WordDocument document = new WordDocument("Template.docx",FormatType.Docx))
 {
     //Get the paragraph.
     WParagraph paragraph = document.LastParagraph;
     //Get the chart entity.
     WChart chart = paragraph.ChildEntities[0] as WChart;
     //Modify the chart height and width.
     chart.Height = 300;
     chart.Width = 500;

     //Plot Area.
     IOfficeChartFrameFormat chartPlotArea = chart.PlotArea;

     //Plot area border settings - line pattern, color, weight.
     chartPlotArea.Border.LinePattern = OfficeChartLinePattern.Solid;
     chartPlotArea.Border.LineColor = Color.Blue;
     chartPlotArea.Border.LineWeight = OfficeChartLineWeight.Hairline;

     //Set fill type and color.
     chartPlotArea.Fill.FillType = OfficeFillType.Gradient;
     chartPlotArea.Fill.GradientColorType = OfficeGradientColor.TwoColor;
     chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234);
     chartPlotArea.Fill.ForeColor = Color.White;
     //Save the Word file.
     document.Save("Sample.docx");
 }
Using document As New WordDocument("Template.docx", FormatType.Docx)
    ' Get the paragraph.
    Dim paragraph As WParagraph = document.LastParagraph
    ' Get the chart entity.
    Dim chart As WChart = TryCast(paragraph.ChildEntities(0), WChart)

    ' Modify the chart height and width.
    chart.Height = 300
    chart.Width = 500

    ' Plot Area.
    Dim chartPlotArea As IOfficeChartFrameFormat = chart.PlotArea

    ' Plot area border settings - line pattern, color, weight.
    chartPlotArea.Border.LinePattern = OfficeChartLinePattern.Solid
    chartPlotArea.Border.LineColor = Color.Blue
    chartPlotArea.Border.LineWeight = OfficeChartLineWeight.Hairline

    ' Set fill type and color.
    chartPlotArea.Fill.FillType = OfficeFillType.Gradient
    chartPlotArea.Fill.GradientColorType = OfficeGradientColor.TwoColor
    chartPlotArea.Fill.BackColor = Color.FromArgb(205, 217, 234)
    chartPlotArea.Fill.ForeColor = Color.White

    ' Save the Word file.
    document.Save("Sample.docx")
End Using

You can download a complete working sample from GitHub.

Add Image in Plot Area

The following code snippet illustrates how to fill the image in plot area.

//Appeend image in plot area.
FileStream imageStream = new FileStream("Data/Image.png", FileMode.Open, FileAccess.Read);
Image image = Image.FromStream(imageStream);
chartPlotArea.Fill.UserPicture(image, "image");
//Appeend image in plot area.
chartPlotArea.Fill.UserPicture("Image.png");
' Append an image to the chart plot area.
chartPlotArea.Fill.UserPicture("Image.png")

Set the Transparency level

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

// Set the transparency of the plot area.
chartPlotArea.Fill.Transparency = 0.5;
// Set the transparency of the plot area.
chartPlotArea.Fill.Transparency = 0.5;
' Set the transparency of the plot area.
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 the position of Plot Area

The following code snippet illustrates how to position the plot area in chart.

//Sets position for plot area.
chartPlotArea.Layout.LeftMode = LayoutModes.auto;
chartPlotArea.Layout.TopMode = LayoutModes.factor;
chartPlotArea.Layout.LayoutTarget = LayoutTargets.outer;
//Sets position for plot area.
chartPlotArea.Layout.LeftMode = LayoutModes.auto;
chartPlotArea.Layout.TopMode = LayoutModes.factor;
chartPlotArea.Layout.LayoutTarget = LayoutTargets.outer;
' Sets position for plot area.
chartPlotArea.Layout.LeftMode = LayoutModes.auto
chartPlotArea.Layout.TopMode = LayoutModes.factor
chartPlotArea.Layout.LayoutTarget = LayoutTargets.outer