When you generate a Word report, you can format a chart’s plot area to complement the rest of the document. The plot area is where the chart displays its data. It sits inside the larger chart area, which can also contain a title and legend.

This tutorial shows you how to create a column chart in C#, apply a gradient fill and a border to its plot area, and save the chart in a Word document.

C# Library to Format a Word Chart Plot Area

Aspose.Words for .NET lets you create and work with Word documents in .NET applications. The plot-area fill and line formatting API is available in version 26.10 or later.

Add the package to your project using the .NET CLI:

dotnet add package Aspose.Words --version 26.10.0

You can use the library in evaluation mode or request a free temporary license to evaluate it without evaluation limitations.

Format the Plot Area of a Word Chart in C#

Follow these steps to create and format a chart:

  1. Create a Document and a DocumentBuilder.
  2. Insert a column chart with InsertChart() and access the chart through the returned shape.
  3. Clear the default series and add your own categories and values.
  4. Access Chart.PlotArea.Format.
  5. Apply a gradient fill and set the border color and width.
  6. Save the document as a DOCX file.

The following complete example creates a chart with two series and formats its plot area:

using System.Drawing;
using Aspose.Words;
using Aspose.Words.Drawing;
using Aspose.Words.Drawing.Charts;

class Program
{
    static void Main()
    {
        // Create a document and insert a column chart.
        Document doc = new Document();
        DocumentBuilder builder = new DocumentBuilder(doc);
        Shape shape = builder.InsertChart(ChartType.Column, 432, 252);
        Chart chart = shape.Chart;

        // Replace the default series with sample data.
        chart.Series.Clear();
        string[] categories = { "Quarter 1", "Quarter 2" };
        chart.Series.Add("2025", categories, new double[] { 1, 2 });
        chart.Series.Add("2026", categories, new double[] { 3, 4 });

        // Set the plot-area fill and border.
        ChartPlotArea plotArea = chart.PlotArea;
        plotArea.Format.Fill.OneColorGradient(
            Color.LightBlue, GradientStyle.DiagonalUp,
            GradientVariant.Variant2, 1);
        plotArea.Format.Stroke.ForeColor = Color.Blue;
        plotArea.Format.Stroke.Weight = 0.25;

        // Save the document.
        doc.Save("formatted-chart-csharp.docx");
    }
}

How the Plot Area Formatting Works

A newly inserted chart contains generated data. The example clears its series and adds two new series with values for the same two categories.

The Chart.PlotArea.Format property provides access to the plot area’s fill and line formatting. OneColorGradient() sets the gradient color, style, variant, and degree. Stroke.ForeColor sets the border color, while Stroke.Weight sets its width; the example uses 0.25 points.

View the Formatted Chart

Open formatted-chart-csharp.docx in a Word document viewer. The document contains a column chart with two data series, a light-blue gradient in the plot area, and a thin blue border. Change the data and formatting values to match your report.

Format the Plot Area of a Word Chart.

Format the Plot Area of a Word Chart.

Conclusion

You have created a Word column chart and customized its plot area using C#. Try different colors and data in your own reports, and see how to create charts in Word using C# for more chart examples.

See Also