Back to Devexpress

Charts in Word Documents

officefileapi-403074-word-processing-document-api-word-processing-document-charts.md

latest29.1 KB
Original Source

Charts in Word Documents

  • Mar 12, 2024
  • 14 minutes to read

The Word Processing Document API uses Spreadsheet Chart API to import, generate, save, print, and export documents with charts to PDF. You can create 2-D and 3-D charts in code, apply chart styles, and format individual chart elements.

Important

You need a license to the DevExpress Office File API or DevExpress Universal Subscription to use spreadsheet charts in production code. Refer to the DevExpress Subscription page for pricing information.

Enable Charts for the Word Processing Document API

Follow the steps below to enable spreadsheet charts in your word processing app:

  1. Add references to the following assemblies:

  2. Call the following method before you create a RichEditDocumentServer instance:

Create Charts

Charts are stored in the SubDocument.Shapes collection. Use the ShapeCollection.InsertChart method to add a chart to a document. Pass a ChartType enumeration member to this method to specify the chart type.

Use the following properties to populate the chart with data:

Shape.ChartFormat.ChartCast this property value to DevExpress.Spreadsheet.Charts.ChartObject to obtain a spreadsheet chart associated with the inserted chart object. Use the Spreadsheet Chart API to specify chart settings (select the source data, define series options, and specify the chart layout).Shape.ChartFormat.WorksheetCast this property value to a DevExpress.Spreadsheet.Worksheet object to obtain a worksheet that stores chart data.

Create a Simple Chart

The following code snippet adds a Pareto chart to a document:

csharp
using DevExpress.Office.Services;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Spreadsheet.Charts;
using DevExpress.Spreadsheet;
using System.Drawing;
// ...

Document document = wordProcessor.Document;
// Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Create a Pareto chart.
var chartShape = document.Shapes.InsertChart(document.Range.Start, 
    DevExpress.XtraRichEdit.API.Native.ChartType.Pareto);
chartShape.Name = "Pareto chart";
// Specify the chart size and position.
chartShape.Size = new System.Drawing.SizeF(6, 4);
chartShape.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column;
chartShape.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph;
chartShape.Offset = new PointF(0, 0);

// Access the spreadsheet chart object.
ChartObject chart = (ChartObject)chartShape.ChartFormat.Chart;
// Access a worksheet that stores chart data.
Worksheet worksheet = (Worksheet)chartShape.ChartFormat.Worksheet;
// Populate the worksheet with data.
SpecifyChartData(worksheet);
// Select chart data.
chart.SelectData(worksheet["B2:C7"]);

// Specify series options.
var options = chart.Series[0].LayoutOptions.Histogram;
options.BinType = HistogramBinType.ByCategory;
// Specify the gap width.
chart.Series[0].GapWidth = 15;

// Add the chart title.
chart.Title.Visible = true;
chart.Title.SetValue("Key Causes of Late Projects");

private static void SpecifyChartData(Worksheet sheet)
{
    // The first column.
    sheet["B2"].Value = "Key causes of late projects";
    sheet["B3"].Value = "Poor specification";
    sheet["B4"].Value = "Poor planning";
    sheet["B5"].Value = "Lack of support";
    sheet["B6"].Value = "Lack of resources";
    sheet["B7"].Value = "Technology issues";
    // The second column.
    sheet["C2"].Value = "Frequency of occurrences";
    sheet["C3"].Value = 16;
    sheet["C4"].Value = 20;
    sheet["C5"].Value = 3;
    sheet["C6"].Value = 4;
    sheet["C7"].Value = 1;
}
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Spreadsheet.Charts
Imports DevExpress.Spreadsheet
Imports System.Drawing
' ...

Dim document As Document = wordProcessor.Document
' Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Create a Pareto chart.
Dim chartShape As DevExpress.XtraRichEdit.API.Native.Shape = 
    document.Shapes.InsertChart(document.Range.Start, 
    DevExpress.XtraRichEdit.API.Native.ChartType.Pareto)
chartShape.Name = "Pareto chart"
' Specify the chart size and position.
chartShape.Size = New System.Drawing.SizeF(6, 4)
chartShape.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column
chartShape.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph
chartShape.Offset = New PointF(0, 0)

' Access the spreadsheet chart object.
Dim chart As ChartObject = CType(chartShape.ChartFormat.Chart, ChartObject)
' Access a worksheet that stores chart data.
Dim worksheet As Worksheet = CType(chartShape.ChartFormat.Worksheet, Worksheet)
' Populate the worksheet with data.
SpecifyChartData(worksheet)
' Select chart data.
chart.SelectData(worksheet("B2:C7"))

' Specify series options.
Dim options As HistogramSeriesOptions = 
    chart.Series(0).LayoutOptions.Histogram
options.BinType = HistogramBinType.ByCategory
' Specify the gap width.
chart.Series(0).GapWidth = 15

' Add the chart title.
chart.Title.Visible = True
chart.Title.SetValue("Key Causes of Late Projects")

Private Sub SpecifyChartData(ByVal sheet As Worksheet)
    ' The first column.
    sheet("B2").Value = "Key causes of late projects"
    sheet("B3").Value = "Poor specification"
    sheet("B4").Value = "Poor planning"
    sheet("B5").Value = "Lack of support"
    sheet("B6").Value = "Lack of resources"
    sheet("B7").Value = "Technology issues"
    ' The second column.
    sheet("C2").Value = "Frequency of occurrences"
    sheet("C3").Value = 16
    sheet("C4").Value = 20
    sheet("C5").Value = 3
    sheet("C6").Value = 4
    sheet("C7").Value = 1
End Sub

Create a Combination Chart

The Spreadsheet Chart API allows you to create a combination chart that includes data series of different chart types. Use the Series.ChangeType method to change the series type.

Important

There are chart types that cannot be combined (for example, you cannot display 2-D and 3-D series on a chart). Refer to the following topic for a list of compatible chart types: How to: Create and Modify a Chart

The following code snippet creates a chart that combines a column and a line data series:

csharp
using DevExpress.Office.Services;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Spreadsheet.Charts;
using DevExpress.Spreadsheet;
using System.Drawing;
// ...

Document document = wordProcessor.Document;
// Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Create a clustered column chart.
var chartShape = document.Shapes.InsertChart(document.Range.Start, 
    DevExpress.XtraRichEdit.API.Native.ChartType.ColumnClustered);
chartShape.Name = "Combo chart";
// Specify the chart size and position.
chartShape.Size = new System.Drawing.SizeF(6, 4);
chartShape.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column;
chartShape.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph;
chartShape.Offset = new PointF(0, 0);

// Access the spreadsheet chart object.
ChartObject chart = (ChartObject)chartShape.ChartFormat.Chart;
// Access a worksheet that stores chart data.
Worksheet worksheet = (Worksheet)chartShape.ChartFormat.Worksheet;
// Populate the worksheet with data.
SpecifyChartData(worksheet);
// Select chart data.
chart.SelectData(worksheet["B2:D8"]);

// Change the second series type.
chart.Series[1].ChangeType(DevExpress.Spreadsheet.Charts.ChartType.LineMarker);

// Display the secondary axis.
chart.Series[1].AxisGroup = AxisGroup.Secondary;

// Position the chart legend.
chart.Legend.Position = LegendPosition.Bottom;

private static void SpecifyChartData(Worksheet sheet)
{
    // The first column.
    sheet["B2"].Value = "Month";
    sheet["B3"].Value = "January";
    sheet["B4"].Value = "February";
    sheet["B5"].Value = "March";
    sheet["B6"].Value = "April";
    sheet["B7"].Value = "May";
    sheet["B8"].Value = "June";
    // The second column.
    sheet["C2"].Value = "Units Sold";
    sheet["C3"].Value = 50;
    sheet["C4"].Value = 100;
    sheet["C5"].Value = 30;
    sheet["C6"].Value = 104;
    sheet["C7"].Value = 87;
    sheet["C8"].Value = 150;
    // The third column.
    sheet["D2"].Value = "Total Transactions";
    sheet["D3"].Value = 900;
    sheet["D4"].Value = 3000;
    sheet["D5"].Value = 1200;
    sheet["D6"].Value = 7000;
    sheet["D7"].Value = 5100;
    sheet["D8"].Value = 7500;
}
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Spreadsheet.Charts
Imports DevExpress.Spreadsheet
Imports System.Drawing
' ...

Dim document As Document = wordProcessor.Document
' Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Create a clustered column chart.
Dim chartShape As DevExpress.XtraRichEdit.API.Native.Shape = 
    document.Shapes.InsertChart(document.Range.Start, 
    DevExpress.XtraRichEdit.API.Native.ChartType.ColumnClustered)
chartShape.Name = "Combo chart"
' Specify the chart size and position.
chartShape.Size = New System.Drawing.SizeF(6, 4)
chartShape.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column
chartShape.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph
chartShape.Offset = New PointF(0, 0)

' Access the spreadsheet chart object.
Dim chart As ChartObject = CType(chartShape.ChartFormat.Chart, ChartObject)
' Access a worksheet that stores chart data.
Dim worksheet As Worksheet = CType(chartShape.ChartFormat.Worksheet, Worksheet)
' Populate the worksheet with data.
SpecifyChartData(worksheet)
' Select chart data.
chart.SelectData(worksheet("B2:D8"))

' Change the second series type.
chart.Series(1).ChangeType(DevExpress.Spreadsheet.Charts.ChartType.LineMarker)

' Display the secondary axis.
chart.Series(1).AxisGroup = AxisGroup.Secondary

' Position the chart legend.
chart.Legend.Position = LegendPosition.Bottom

Private Sub SpecifyChartData(ByVal sheet As Worksheet)
    ' The first column.
    sheet("B2").Value = "Month"
    sheet("B3").Value = "January"
    sheet("B4").Value = "February"
    sheet("B5").Value = "March"
    sheet("B6").Value = "April"
    sheet("B7").Value = "May"
    sheet("B8").Value = "June"
    ' The second column.
    sheet("C2").Value = "Units Sold"
    sheet("C3").Value = 50
    sheet("C4").Value = 100
    sheet("C5").Value = 30
    sheet("C6").Value = 104
    sheet("C7").Value = 87
    sheet("C8").Value = 150
    ' The third column.
    sheet("D2").Value = "Total Transactions"
    sheet("D3").Value = 900
    sheet("D4").Value = 3000
    sheet("D5").Value = 1200
    sheet("D6").Value = 7000
    sheet("D7").Value = 5100
    sheet("D8").Value = 7500
End Sub

Access Charts

Use the ShapeCollection.Item property to return a chart from a shape collection. The Shape.Type property helps you distinguish between different drawing object types in the document.

The following code snippets returns all clustered column charts from the document. The ChartObject.ChartType property is used to find charts of the required type.

csharp
using DevExpress.Office.Services;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Spreadsheet.Charts;
using System.Collections.Generic;
using System.Linq;
// ...

Document document = wordProcessor.Document;
List<DevExpress.XtraRichEdit.API.Native.Shape> columnCharts = document.Shapes
    .Where(x => x.Type == DevExpress.XtraRichEdit.API.Native.ShapeType.Chart &&
    ((ChartObject)x.ChartFormat.Chart).ChartType == DevExpress.Spreadsheet.Charts.ChartType.ColumnClustered)
    .ToList();
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Spreadsheet.Charts
Imports System.Collections.Generic
Imports System.Linq
' ...

Dim document As Document = wordProcessor.Document
Dim columnCharts As List(Of DevExpress.XtraRichEdit.API.Native.Shape) = document.Shapes() _
Where(Function(x) x.Type = DevExpress.XtraRichEdit.API.Native.ShapeType.Chart AndAlso _
CType(x.ChartFormat.Chart, ChartObject).ChartType = DevExpress.Spreadsheet.Charts.ChartType.ColumnClustered) _
.ToList()

Change the Chart Layout

The Spreadsheet Chart API allows you to add or remove different chart elements:

The following example demonstrates how to create a clustered column chart and specify its layout:

csharp
using DevExpress.Office.Services;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Spreadsheet.Charts;
using DevExpress.Spreadsheet;
using System.Drawing;
// ...

Document document = wordProcessor.Document;
// Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch;
// Create a clustered column chart.
var chartShape = document.Shapes.InsertChart(document.Range.Start, 
    DevExpress.XtraRichEdit.API.Native.ChartType.ColumnClustered);
chartShape.Name = "Largest countries chart";
// Specify the chart size and position.
chartShape.Size = new System.Drawing.SizeF(6, 4);
chartShape.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column;
chartShape.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph;
chartShape.Offset = new PointF(0, 0);

// Access the spreadsheet chart object.
ChartObject chart = (ChartObject)chartShape.ChartFormat.Chart;
// Access a worksheet that stores chart data.
Worksheet worksheet = (Worksheet)chartShape.ChartFormat.Worksheet;
// Populate the worksheet with data.
SpecifyChartData(worksheet);
// Select chart data.
chart.SelectData(worksheet["B2:C7"]);

// Display the chart title.
chart.Title.Visible = true;
chart.Title.SetValue("Top 5 Largest Countries by Area");

// Access the value axis.
Axis valueAxis = chart.PrimaryAxes[1];
// Set minimum and maximum scale values.
valueAxis.Scaling.AutoMax = false;
valueAxis.Scaling.Max = 18000000;
valueAxis.Scaling.AutoMin = false;
valueAxis.Scaling.Min = 0;
// Specify the distance between major tick marks.
valueAxis.MajorUnit = 2000000;
// Specify display units for the value axis.
valueAxis.DisplayUnits.UnitType = DisplayUnitType.Millions;
valueAxis.DisplayUnits.ShowLabel = true;
// Specify the axis title.
valueAxis.Title.Visible = true;
valueAxis.Title.SetValue("Total area (square kilometers in millions)");
// Display major gridlines.
valueAxis.MajorGridlines.Visible = true;

// Hide the chart legend.
chart.Legend.Visible = false;

private static void SpecifyChartData(Worksheet sheet)
{
    // The first column.
    sheet["B2"].Value = "Country";
    sheet["B3"].Value = "Russia";
    sheet["B4"].Value = "Canada";
    sheet["B5"].Value = "USA";
    sheet["B6"].Value = "China";
    sheet["B7"].Value = "Brazil";
    // The second column.
    sheet["C2"].Value = "Total Area";
    sheet["C3"].Value = 17098246;
    sheet["C4"].Value = 9984670;
    sheet["C5"].Value = 9833517;
    sheet["C6"].Value = 9596961;
    sheet["C7"].Value = 8515767;
}
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Spreadsheet.Charts
Imports DevExpress.Spreadsheet
Imports System.Drawing
' ...

Dim document As Document = wordProcessor.Document
' Set measurement unit to inches.
document.Unit = DevExpress.Office.DocumentUnit.Inch
' Create a clustered column chart.
Dim chartShape As DevExpress.XtraRichEdit.API.Native.Shape = 
    document.Shapes.InsertChart(document.Range.Start, 
    DevExpress.XtraRichEdit.API.Native.ChartType.ColumnClustered)
chartShape.Name = "Largest countries chart"
' Specify the chart size and position.
chartShape.Size = New System.Drawing.SizeF(6, 4)
chartShape.RelativeHorizontalPosition = ShapeRelativeHorizontalPosition.Column
chartShape.RelativeVerticalPosition = ShapeRelativeVerticalPosition.Paragraph
chartShape.Offset = New PointF(0, 0)

' Access the spreadsheet chart object.
Dim chart As ChartObject = CType(chartShape.ChartFormat.Chart, ChartObject)
' Access a worksheet that stores chart data.
Dim worksheet As Worksheet = CType(chartShape.ChartFormat.Worksheet, Worksheet)
' Populate the worksheet with data.
SpecifyChartData(worksheet)
' Select chart data.
chart.SelectData(worksheet("B2:C7"))

' Display the chart title.
chart.Title.Visible = True
chart.Title.SetValue("Top 5 Largest Countries by Area")

' Access the value axis.
Dim valueAxis As Axis = chart.PrimaryAxes(1)
' Set minimum and maximum scale values.
valueAxis.Scaling.AutoMax = False
valueAxis.Scaling.Max = 18000000
valueAxis.Scaling.AutoMin = False
valueAxis.Scaling.Min = 0
' Specify the distance between major tick marks.
valueAxis.MajorUnit = 2000000
' Specify display units for the value axis.
valueAxis.DisplayUnits.UnitType = DisplayUnitType.Millions
valueAxis.DisplayUnits.ShowLabel = True
' Specify the axis title.
valueAxis.Title.Visible = True
valueAxis.Title.SetValue("Total area (square kilometers in millions)")
' Display major gridlines.
valueAxis.MajorGridlines.Visible = True

' Hide the chart legend.
chart.Legend.Visible = False

Private Sub SpecifyChartData(ByVal sheet As Worksheet)
    ' The first column.
    sheet("B2").Value = "Country"
    sheet("B3").Value = "Russia"
    sheet("B4").Value = "Canada"
    sheet("B5").Value = "USA"
    sheet("B6").Value = "China"
    sheet("B7").Value = "Brazil"
    ' The second column.
    sheet("C2").Value = "Total Area"
    sheet("C3").Value = 17098246
    sheet("C4").Value = 9984670
    sheet("C5").Value = 9833517
    sheet("C6").Value = 9596961
    sheet("C7").Value = 8515767
End Sub

Change the Chart Type

Use the ChartObject.ChangeType method to change the type of an existing chart. If the operation cannot be completed, an exception occurs.

The following example converts a clustered column chart into a clustered bar chart:

csharp
using DevExpress.Office.Services;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Spreadsheet.Charts;
// ...

Document document = wordProcessor.Document;
document.LoadDocument("Charts.docx");
// Return a chart with the specified name. 
var chartShape = document.Shapes["Largest countries chart"];
if(chartShape != null)
{
    // Access the spreadsheet chart object.
    ChartObject chart = (ChartObject)chartShape.ChartFormat.Chart;

    // Change the chart type.
    chart.ChangeType(DevExpress.Spreadsheet.Charts.ChartType.BarClustered);
}
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Spreadsheet.Charts
' ...

Dim document As Document = wordProcessor.Document
document.LoadDocument("Charts.docx")
' Return a chart with the specified name. 
Dim chartShape As Shape = document.Shapes("Largest countries chart")
If chartShape IsNot Nothing Then
    ' Access the spreadsheet chart object.
    Dim chart As ChartObject = CType(chartShape.ChartFormat.Chart, ChartObject)

    ' Change the chart type.
    chart.ChangeType(DevExpress.Spreadsheet.Charts.ChartType.BarClustered)
End If

Format Chart Elements

Apply a Chart Style

Use the ChartObject.Style property to apply one of the predefined styles to a chart. Each style specifies data series colors, sets the chart’s background fill, applies different shape effects and outlines to the chart.

The following example applies the Accent2Bevel style to a chart:

csharp
using DevExpress.Office.Services;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Spreadsheet.Charts;
// ...

Document document = wordProcessor.Document;
document.LoadDocument("Charts.docx");
// Return a chart with the specified name. 
var chartShape = document.Shapes["Largest countries chart"];
if(chartShape != null)
{
    // Access the spreadsheet chart object.
    ChartObject chart = (ChartObject)chartShape.ChartFormat.Chart;

    // Apply a chart style.
    chart.Style = ChartStyle.Accent2Bevel;
}
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Spreadsheet.Charts
' ...

Dim document As Document = wordProcessor.Document
document.LoadDocument("Charts.docx")
' Return a chart with the specified name. 
Dim chartShape As Shape = document.Shapes("Largest countries chart")
If chartShape IsNot Nothing Then
    ' Access the spreadsheet chart object.
    Dim chart As ChartObject = CType(chartShape.ChartFormat.Chart, ChartObject)

    ' Apply a chart style.
    chart.Style = ChartStyle.Accent2Bevel
End If

Format Individual Elements

Chart elements (ChartObject, Series, DataPoint, Axis, DataLabel, ChartTitle, and so on) are inherited from the ShapeFormatBase and ShapeTextFormat interfaces. These interfaces contain the following options to change the appearance of chart elements:

ShapeFormatBase.FillDefines fill options.ShapeFormatBase.OutlineReturns format settings for line elements (axes, gridlines, line series, and so on) or a chart element’s border.ShapeTextFormat.FontSpecifies font characteristics for text labels on the chart.

The following code snippet demonstrates how to change the appearance of individual chart elements:

csharp
using DevExpress.Office.Services;
using DevExpress.XtraSpreadsheet.Services;
using DevExpress.XtraRichEdit.API.Native;
using DevExpress.Spreadsheet.Charts;
using System.Drawing;
using DevExpress.Spreadsheet.Drawings;
// ...

Document document = wordProcessor.Document;
document.LoadDocument("Charts.docx");
// Return a chart with the specified name. 
var chartShape = document.Shapes["Largest countries chart"];
if(chartShape != null)
{
    // Access the spreadsheet chart object.
    ChartObject chart = (ChartObject)chartShape.ChartFormat.Chart;

    //Specify that each data point has a different color.
    chart.Views[0].VaryColors = true;

    // Make the plot area transparent.
    chart.PlotArea.Fill.SetNoFill();

    // Apply a gradient fill to the chart area.
    chart.Fill.SetGradientFill(ShapeGradientType.Linear, Color.FromArgb(0xFF, 0xFF, 0xFF), 
        Color.FromArgb(0xEC, 0xE9, 0xE6));
    chart.Fill.GradientFill.Angle = 90;

    // Change font color for the chart title.
    chart.Title.Font.Color = Color.FromArgb(0x1D, 0x2B, 0x64);
}
vb
Imports DevExpress.Office.Services
Imports DevExpress.XtraSpreadsheet.Services
Imports DevExpress.XtraRichEdit.API.Native
Imports DevExpress.Spreadsheet.Charts
Imports System.Drawing
Imports DevExpress.Spreadsheet.Drawings
' ...

Dim document As Document = wordProcessor.Document
document.LoadDocument("Charts.docx")
' Return a chart with the specified name. 
Dim chartShape As Shape = document.Shapes("Largest countries chart")
If chartShape IsNot Nothing Then
    ' Access the spreadsheet chart object.
    Dim chart As ChartObject = CType(chartShape.ChartFormat.Chart, ChartObject)

    'Specify that each data point has a different color.
    chart.Views(0).VaryColors = True

    ' Make the plot area transparent.
    chart.PlotArea.Fill.SetNoFill()

    ' Apply a gradient fill to the chart area.
    chart.Fill.SetGradientFill(ShapeGradientType.Linear, Color.FromArgb(&HFF, &HFF, &HFF), 
        Color.FromArgb(&HEC, &HE9, &HE6))
    chart.Fill.GradientFill.Angle = 90

    ' Change font color for the chart title.
    chart.Title.Font.Color = Color.FromArgb(&H1D, &H2B, &H64)
End If

Remove Charts

Use one of the following methods to remove a chart from the document:

The following example removes all charts from the collection:

csharp
Document document = wordProcessor.Document;
var shapes = document.Shapes;
for (int i = shapes.Count - 1; i >= 0; i--)
{
    if (shapes[i].Type == DevExpress.XtraRichEdit.API.Native.ShapeType.Chart)
    shapes.Remove(shapes[i]);
}
vb
Dim document As Document = wordProcessor.Document
Dim shapes As DevExpress.XtraRichEdit.API.Native.ShapeCollection = document.Shapes
For i As Integer = shapes.Count - 1 To 0 Step -1
    If shapes(i).Type = DevExpress.XtraRichEdit.API.Native.ShapeType.Chart Then
    shapes.Remove(shapes(i))
    End If
Next i

Limitations

The Word Processing Document API does not support charts in OpenDocument Text (.odt) documents and encrypted DOC files.

See Also

Shapes, Pictures, and Other Graphic Objects in Word Documents

Spreadsheet Charts