Create Various Types of Charts in Word Documents in C# and VB.NET

Charts can help communicate complex data at a glance and make it easier for readers to understand trends, patterns, and relationships within the data. You may need to create charts in a Word document when you want to visually represent data or information for better understanding. For example, if you're creating a report on sales data, adding a chart showing the revenue generated over a period of time can quickly give your audience a clear view of the company's performance. Similarly, if you're presenting survey results, a pie chart or bar graph can help visualize the percentage distribution of responses. Charts can also be useful for comparing data across different categories or variables, such as comparing the performance of different departments or products. By creating charts in your Word document, you can enhance the impact of your content and make it more engaging and informative for your readers. In this article, we will explore how to create various types of charts in a Word document using C# and VB.NET.

Installation

To create charts in Word documents, you will need to use an appropriate library. One of the popular libraries for this task is Microsoft Word Interop, but it has limitations such as requiring Microsoft Word to be installed and not being recommended for server-side usage. To circumvent this issue, we'll be utilizing the Free Spire.Doc for .NET library which allows for manipulating Word documents without relying on Microsoft Office. You can follow these steps to install the library via NuGet:

  1. Open the Package Manager Console.
  2. Execute this command: Install-Package FreeSpire.Doc

Create Various Types of Charts in Word Documents in C# and VB.NET

Once you have completed the installation, you can start creating charts in your Word documents. The following are the basic steps involved in creating a chart:

  1. Initialize an instance of the Document class.
  2. Add a section using Document.AddSection() method.
  3. Add a paragraph to the section using Section.AddParagraph() method.
  4. Add a chart shape to the paragraph using Paragraph.AppendChart() method.
  5. Access the chart object using ShapeObject.Chart property.
  6. Add data series to the chart using Chart.Series.Add() method.
  7. Save the result document using Document.SaveToFile() method.

Now you know the basic steps for creating charts in a Word document, let's take a look at how you can create different types of charts, for example, column charts, line charts, pie charts, scatter charts, bar charts, bubble charts, and 3D surface charts. 

Create a Column Chart in Word in C# and VB.NET

A column chart is a great way to compare data across categories. To create a column chart in Word using C# or VB.NET, you can use the following code:

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Fields.Shapes.Charts;

namespace CreateColumnCharts
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a word document
            Document document = new Document();

            //Create a new section
            Section section = document.AddSection();
            section.PageSetup.Margins.All = 72f;

            //Create a new paragraph and append text
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Column Chart");
            paragraph.ApplyStyle(BuiltinStyle.Heading1);

            //Create a new paragraph to append a column chart shape
            paragraph = section.AddParagraph();
            ShapeObject shape = paragraph.AppendChart(ChartType.Column, 300, 200);

            //Clear the default series of the chart
            Chart chart = shape.Chart;
            chart.Series.Clear();

            //Specify chart data
            string[] categories = new[] { "QTR1", "QTR2", "QTR3", "QTR4"};
            double[] values1 = new double[] { 190000, 85000, 210000, 60000};
            double[] values2 = new double[] { 230000, 100000, 250000, 120000 };

            //Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1);
            chart.Series.Add("ASIA SALES 2010", categories, values2);

            //Set chart title
            chart.Title.Text = "ASIA SALES";
            //Set the number format of the Y-axis tick labels to group digits with commas
            chart.AxisY.NumberFormat.FormatCode = "#,##0";

            //Save the result document
            document.SaveToFile("ColumnChart.docx", FileFormat.Docx2013);
            document.Dispose();
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Fields.Shapes.Charts

Namespace CreateColumnCharts
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a word document
            Dim document As Document = New Document()

            'Create a new section
            Dim section As Section = document.AddSection()
            section.PageSetup.Margins.All = 72F

            'Create a new paragraph and append text
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("Column Chart")
            paragraph.ApplyStyle(BuiltinStyle.Heading1)

            'Create a new paragraph to append a column chart shape
            paragraph = section.AddParagraph()
            Dim shape As ShapeObject = paragraph.AppendChart(ChartType.Column, 300, 200)

            'Clear the default series of the chart
            Dim chart As Chart = shape.Chart
            chart.Series.Clear()

            'Specify chart data
            Dim categories = {"QTR1", "QTR2", "QTR3", "QTR4"}
            Dim values1 = New Double() {190000, 85000, 210000, 60000}
            Dim values2 = New Double() {230000, 100000, 250000, 120000}

            'Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1)
            chart.Series.Add("ASIA SALES 2010", categories, values2)

            'Set chart title
            chart.Title.Text = "ASIA SALES"
            'Set the number format of the Y-axis tick labels to group digits with commas
            chart.AxisY.NumberFormat.FormatCode = "#,##0"

            'Save the result document
            document.SaveToFile("ColumnChart.docx", FileFormat.Docx2013)
            document.Dispose()
        End Sub
    End Class
End Namespace

Column Chart in Word in C# and VB.NET

Create a Line Chart in Word in C# and VB.NET

A line chart is best used to show trends over time. To create a line chart in Word using C# or VB.NET, you can use the following code:

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Fields.Shapes.Charts;

namespace CreateLineCharts
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a word document
            Document document = new Document();

            //Create a new section
            Section section = document.AddSection();
            section.PageSetup.Margins.All = 72f;

            //Create a new paragraph and append text
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Line Chart");
            paragraph.ApplyStyle(BuiltinStyle.Heading1);

            //Create a new paragraph to append a line chart shape
            paragraph = section.AddParagraph();
            ShapeObject shape = paragraph.AppendChart(ChartType.Line, 300, 200);

            //Clear the default series of the chart
            Chart chart = shape.Chart;
            chart.Series.Clear();

            //Specify chart data
            string[] categories = new[] { "QTR1", "QTR2", "QTR3", "QTR4" };
            double[] values1 = new double[] { 190000, 85000, 210000, 60000 };
            double[] values2 = new double[] { 230000, 100000, 250000, 120000 };

            //Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1);
            chart.Series.Add("ASIA SALES 2010", categories, values2);

            //Set chart title
            chart.Title.Text = "ASIA SALES";
            //Set the number format of the Y-axis tick labels to group digits with commas
            chart.AxisY.NumberFormat.FormatCode = "#,##0";

            //Save the result document
            document.SaveToFile("LineChart.docx", FileFormat.Docx2013);
            document.Dispose();
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Fields.Shapes.Charts

Namespace CreateLineCharts
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a word document
            Dim document As Document = New Document()

            'Create a new section
            Dim section As Section = document.AddSection()
            section.PageSetup.Margins.All = 72F

            'Create a new paragraph and append text
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("Line Chart")
            paragraph.ApplyStyle(BuiltinStyle.Heading1)

            'Create a new paragraph to append a line chart shape
            paragraph = section.AddParagraph()
            Dim shape As ShapeObject = paragraph.AppendChart(ChartType.Line, 300, 200)

            'Clear the default series of the chart
            Dim chart As Chart = shape.Chart
            chart.Series.Clear()

            'Specify chart data
            Dim categories = {"QTR1", "QTR2", "QTR3", "QTR4"}
            Dim values1 = New Double() {190000, 85000, 210000, 60000}
            Dim values2 = New Double() {230000, 100000, 250000, 120000}

            'Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1)
            chart.Series.Add("ASIA SALES 2010", categories, values2)

            'Set chart title
            chart.Title.Text = "ASIA SALES"
            'Set the number format of the Y-axis tick labels to group digits with commas
            chart.AxisY.NumberFormat.FormatCode = "#,##0"

            'Save the result document
            document.SaveToFile("LineChart.docx", FileFormat.Docx2013)
            document.Dispose()
        End Sub
    End Class
End Namespace

Line Chart in Word in C# and VB.NET

Create a Pie Chart in Word in C# and VB.NET

A pie chart is a great way to show proportions. To create a pie chart in Word using C# or VB.NET, you can use the following code:

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Fields.Shapes.Charts;

namespace CreatePieCharts
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a word document
            Document document = new Document();

            //Create a new section
            Section section = document.AddSection();
            section.PageSetup.Margins.All = 72f;

            //Create a new paragraph and append text
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Pie Chart");
            paragraph.ApplyStyle(BuiltinStyle.Heading1);

            //Create a new paragraph to append a pie chart shape
            paragraph = section.AddParagraph();
            ShapeObject shape = paragraph.AppendChart(ChartType.Pie, 300, 200);

            //Clear the default series of the chart
            Chart chart = shape.Chart;
            chart.Series.Clear();

            //Specify chart data
            string[] categories = new[] { "QTR1", "QTR2", "QTR3", "QTR4" };
            double[] values = new double[] { 190000, 85000, 210000, 60000 };

            //Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values);
            
            //Set chart title
            chart.Title.Text = "ASIA SALES 2009";

            //Save the result document
            document.SaveToFile("PieChart.docx", FileFormat.Docx2013);
            document.Dispose();
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Fields.Shapes.Charts

Namespace CreatePieCharts
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a word document
            Dim document As Document = New Document()

            'Create a new section
            Dim section As Section = document.AddSection()
            section.PageSetup.Margins.All = 72F

            'Create a new paragraph and append text
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("Pie Chart")
            paragraph.ApplyStyle(BuiltinStyle.Heading1)

            'Create a new paragraph to append a pie chart shape
            paragraph = section.AddParagraph()
            Dim shape As ShapeObject = paragraph.AppendChart(ChartType.Pie, 300, 200)

            'Clear the default series of the chart
            Dim chart As Chart = shape.Chart
            chart.Series.Clear()

            'Specify chart data
            Dim categories = {"QTR1", "QTR2", "QTR3", "QTR4"}
            Dim values = New Double() {190000, 85000, 210000, 60000}

            'Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values)

            'Set chart title
            chart.Title.Text = "ASIA SALES 2009"

            'Save the result document
            document.SaveToFile("PieChart.docx", FileFormat.Docx2013)
            document.Dispose()
        End Sub
    End Class
End Namespace

Create a Pie Chart in Word in C# and VB.NET

Create a Bar Chart in Word in C# and VB.NET

A bar chart is similar to a column chart, but the bars are horizontal instead of vertical. To create a bar chart in Word using C# or VB.NET, you can use the following code:

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Fields.Shapes.Charts;

namespace CreateBarCharts
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a word document
            Document document = new Document();

            //Create a new section
            Section section = document.AddSection();
            section.PageSetup.Margins.All = 72f;

            //Create a new paragraph and append text
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Bar Chart");
            paragraph.ApplyStyle(BuiltinStyle.Heading1);

            //Create a new paragraph to append a bar chart shape
            paragraph = section.AddParagraph();
            ShapeObject shape = paragraph.AppendChart(ChartType.Bar, 300, 200);

            //Clear the default series of the chart
            Chart chart = shape.Chart;
            chart.Series.Clear();

            //Specify chart data
            string[] categories = new[] { "QTR1", "QTR2", "QTR3", "QTR4" };
            double[] values1 = new double[] { 190000, 85000, 210000, 60000 };
            double[] values2 = new double[] { 230000, 100000, 250000, 120000 };

            //Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1);
            chart.Series.Add("ASIA SALES 2010", categories, values2);

            //Set chart title
            chart.Title.Text = "ASIA SALES";
            //Set the number format of the Y-axis tick labels to group digits with commas
            chart.AxisY.NumberFormat.FormatCode = "#,##0";

            //Save the result document
            document.SaveToFile("BarChart.docx", FileFormat.Docx2013);
            document.Dispose();
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Fields.Shapes.Charts

Namespace CreateBarCharts
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a word document
            Dim document As Document = New Document()

            'Create a new section
            Dim section As Section = document.AddSection()
            section.PageSetup.Margins.All = 72F

            'Create a new paragraph and append text
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("Bar Chart")
            paragraph.ApplyStyle(BuiltinStyle.Heading1)

            'Create a new paragraph to append a bar chart shape
            paragraph = section.AddParagraph()
            Dim shape As ShapeObject = paragraph.AppendChart(ChartType.Bar, 300, 200)

            'Clear the default series of the chart
            Dim chart As Chart = shape.Chart
            chart.Series.Clear()

            'Specify chart data
            Dim categories = {"QTR1", "QTR2", "QTR3", "QTR4"}
            Dim values1 = New Double() {190000, 85000, 210000, 60000}
            Dim values2 = New Double() {230000, 100000, 250000, 120000}

            'Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1)
            chart.Series.Add("ASIA SALES 2010", categories, values2)

            'Set chart title
            chart.Title.Text = "ASIA SALES"
            'Set the number format of the Y-axis tick labels to group digits with commas
            chart.AxisY.NumberFormat.FormatCode = "#,##0"

            'Save the result document
            document.SaveToFile("BarChart.docx", FileFormat.Docx2013)
            document.Dispose()
        End Sub
    End Class
End Namespace

Create a Bar Chart in Word in C# and VB.NET

Create a Scatter Chart in Word in C# and VB.NET

A scatter chart is used to show the relationship between two variables. To create a scatter chart in Word using C# or VB.NET, you can use the following code:

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Fields.Shapes.Charts;

namespace CreateScatterCharts
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a word document
            Document document = new Document();

            //Create a new section
            Section section = document.AddSection();
            section.PageSetup.Margins.All = 72f;

            //Create a new paragraph and append text
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Scatter Chart");
            paragraph.ApplyStyle(BuiltinStyle.Heading1);

            //Create a new paragraph to append a scatter chart shape
            paragraph = section.AddParagraph();
            ShapeObject shape = paragraph.AppendChart(ChartType.Scatter, 300, 200);

            //Clear the default series of the chart
            Chart chart = shape.Chart;
            chart.Series.Clear();

            //Specify chart data
            double[] xValues = new double[] { 4.1, 4.3, 5.7, 5.4, 5.9, 5.0, 3.6, 1.9, 7.3 };
            double[] yValues = new double[] { 122, 117, 112, 114, 110, 114, 128, 137, 104 };

            //Add data series to the chart
            chart.Series.Add("DAILY RAINFALL", xValues, yValues);

            //Set chart title
            chart.Title.Text = "PARTICULATE LEVELS IN RAINFALL";

            //Save the result document
            document.SaveToFile("ScatterChart.docx", FileFormat.Docx2013);
            document.Dispose();
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Fields.Shapes.Charts

Namespace CreateScatterCharts
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a word document
            Dim document As Document = New Document()

            'Create a new section
            Dim section As Section = document.AddSection()
            section.PageSetup.Margins.All = 72F

            'Create a new paragraph and append text
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("Scatter Chart")
            paragraph.ApplyStyle(BuiltinStyle.Heading1)

            'Create a new paragraph to append a scatter chart shape
            paragraph = section.AddParagraph()
            Dim shape As ShapeObject = paragraph.AppendChart(ChartType.Scatter, 300, 200)

            'Clear the default series of the chart
            Dim chart As Chart = shape.Chart
            chart.Series.Clear()

            'Specify chart data
            Dim xValues = New Double() {4.1, 4.3, 5.7, 5.4, 5.9, 5.0, 3.6, 1.9, 7.3}
            Dim yValues = New Double() {122, 117, 112, 114, 110, 114, 128, 137, 104}

            'Add data series to the chart
            chart.Series.Add("DAILY RAINFALL", xValues, yValues)

            'Set chart title
            chart.Title.Text = "PARTICULATE LEVELS IN RAINFALL"

            'Save the result document
            document.SaveToFile("ScatterChart.docx", FileFormat.Docx2013)
            document.Dispose()
        End Sub
    End Class
End Namespace

Create a Scatter Chart in Word in C# and VB.NET

Create a Bubble Chart in Word in C# and VB.NET

A bubble chart is similar to a scatter chart, but it adds a third variable by using the size of the bubbles to represent the value of the third variable. To create a bubble chart in Word using C# or VB.NET, you can use the following code:

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Fields.Shapes.Charts;

namespace CreateBubbleCharts
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a word document
            Document document = new Document();

            //Create a new section
            Section section = document.AddSection();
            section.PageSetup.Margins.All = 72f;

            //Create a new paragraph and append text
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("Bubble Chart");
            paragraph.ApplyStyle(BuiltinStyle.Heading1);

            //Create a new paragraph to append a bubble chart shape
            paragraph = section.AddParagraph();
            ShapeObject shape = paragraph.AppendChart(ChartType.Bubble, 300, 200);

            //Clear the default series of the chart
            Chart chart = shape.Chart;
            chart.Series.Clear();

            //Specify chart data
            double[] xValues = new double[] { 2.9, 3.5, 1.1, 4.0, 4.0 };
            double[] yValues = new double[] { 1.9, 8.5, 2.1, 6.0, 1.5 };
            double[] bubbleSizes = new double[] { 9.0, 4.5, 2.5, 8.0, 5.0 };

            //Add data series to the chart
            chart.Series.Add("DAILY RAINFALL", xValues, yValues, bubbleSizes);

            //Set chart title
            chart.Title.Text = "PARTICULATE LEVELS IN RAINFALL";

            //Save the result document
            document.SaveToFile("BubbleChart.docx", FileFormat.Docx2013);
            document.Dispose();
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Fields.Shapes.Charts

Namespace CreateBubbleCharts
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a word document
            Dim document As Document = New Document()

            'Create a new section
            Dim section As Section = document.AddSection()
            section.PageSetup.Margins.All = 72F

            'Create a new paragraph and append text
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("Bubble Chart")
            paragraph.ApplyStyle(BuiltinStyle.Heading1)

            'Create a new paragraph to append a bubble chart shape
            paragraph = section.AddParagraph()
            Dim shape As ShapeObject = paragraph.AppendChart(ChartType.Bubble, 300, 200)

            'Clear the default series of the chart
            Dim chart As Chart = shape.Chart
            chart.Series.Clear()

            'Specify chart data
            Dim xValues = New Double() {2.9, 3.5, 1.1, 4.0, 4.0}
            Dim yValues = New Double() {1.9, 8.5, 2.1, 6.0, 1.5}
            Dim bubbleSizes = New Double() {9.0, 4.5, 2.5, 8.0, 5.0}

            'Add data series to the chart
            chart.Series.Add("DAILY RAINFALL", xValues, yValues, bubbleSizes)

            'Set chart title
            chart.Title.Text = "PARTICULATE LEVELS IN RAINFALL"

            'Save the result document
            document.SaveToFile("BubbleChart.docx", FileFormat.Docx2013)
            document.Dispose()
        End Sub
    End Class
End Namespace

Create a Bubble Chart in Word in C# and VB.NET

Create a 3D Surface Chart in Word in C# and VB.NET

A 3D surface chart is used to show how data is distributed over a surface. It is a type of chart that uses shading and color to represent values. To create a 3D surface chart in Word using C# or VB.NET, you can use the following code:

C#

using Spire.Doc;
using Spire.Doc.Documents;
using Spire.Doc.Fields;
using Spire.Doc.Fields.Shapes.Charts;

namespace Create3DSurfaceCharts
{
    internal class Program
    {
        static void Main(string[] args)
        {
            //Create a word document
            Document document = new Document();

            //Create a new section
            Section section = document.AddSection();
            section.PageSetup.Margins.All = 72f;

            //Create a new paragraph and append text
            Paragraph paragraph = section.AddParagraph();
            paragraph.AppendText("3D Surface Chart");
            paragraph.ApplyStyle(BuiltinStyle.Heading1);

            //Create a new paragraph to append a 3D Surface chart shape
            paragraph = section.AddParagraph();
            ShapeObject shape = paragraph.AppendChart(ChartType.Surface3D, 300, 200);

            //Clear the default series of the chart
            Chart chart = shape.Chart;
            chart.Series.Clear();

            //Specify chart data
            string[] categories = new[] { "QTR1", "QTR2", "QTR3", "QTR4" };
            double[] values1 = new double[] { 190000, 85000, 210000, 60000};
            double[] values2 = new double[] { 230000, 100000, 250000, 120000};
            double[] values3 = new double[] { 500000, 820000, 1500000, 400000};

            //Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1);
            chart.Series.Add("ASIA SALES 2010", categories, values2);
            chart.Series.Add("ASIA SALES 2011", categories, values3);

            //Set chart title
            chart.Title.Text = "ASIA SALES";

            //Save the result document
            document.SaveToFile("3DSurfaceChart.docx", FileFormat.Docx2013);
            document.Dispose();
        }
    }
}

VB.NET

Imports Spire.Doc
Imports Spire.Doc.Documents
Imports Spire.Doc.Fields
Imports Spire.Doc.Fields.Shapes.Charts

Namespace Create3DSurfaceCharts
    Friend Class Program
        Private Shared Sub Main(ByVal args As String())
            'Create a word document
            Dim document As Document = New Document()

            'Create a new section
            Dim section As Section = document.AddSection()
            section.PageSetup.Margins.All = 72F

            'Create a new paragraph and append text
            Dim paragraph As Paragraph = section.AddParagraph()
            paragraph.AppendText("3D Surface Chart")
            paragraph.ApplyStyle(BuiltinStyle.Heading1)

            'Create a new paragraph to append a 3D Surface chart shape
            paragraph = section.AddParagraph()
            Dim shape As ShapeObject = paragraph.AppendChart(ChartType.Surface3D, 300, 200)

            'Clear the default series of the chart
            Dim chart As Chart = shape.Chart
            chart.Series.Clear()

            'Specify chart data
            Dim categories = {"QTR1", "QTR2", "QTR3", "QTR4"}
            Dim values1 = New Double() {190000, 85000, 210000, 60000}
            Dim values2 = New Double() {230000, 100000, 250000, 120000}
            Dim values3 = New Double() {500000, 820000, 1500000, 400000}

            'Add data series to the chart
            chart.Series.Add("ASIA SALES 2009", categories, values1)
            chart.Series.Add("ASIA SALES 2010", categories, values2)
            chart.Series.Add("ASIA SALES 2011", categories, values3)

            'Set chart title
            chart.Title.Text = "ASIA SALES"

            'Save the result document
            document.SaveToFile("3DSurfaceChart.docx", FileFormat.Docx2013)
            document.Dispose()
        End Sub
    End Class
End Namespace

Create a 3D Surface Chart in Word in C# and VB.NET

Conclusion

Creating charts in a Word document is a great way to visually represent data and information. The Free Spire.Doc for .NET library supports generating various types of charts including but not limited to the chart types covered in this article, you can explore other chart types by yourself.


Similar Articles