Articles in this section
Category / Section

How to create 3D column chart in Word document using C#?

4 mins read

Syncfusion Essential DocIO is a .NET Core Word library used to create, read, and edit Word documents programmatically without Microsoft Word or Interop dependencies. Using this library, you can create 3D column chart in Word document in C#.

What is a 3D column chart?

A 3D column chart uses three axes (horizontal axis, vertical axis, and depth axis), and they compare data points along the horizontal and the depth axes. This chart can be used to compare data across both the categories and the data series.

A 3D Column chart created using the Word library (Essential DocIO) in .NET Core Word library

3D Column Chart in Word document

Steps to create 3D column chart in Word document:

  1. Initialize chart.

Create a chart object by calling the paragraph.AppendChart(446,270) method and specify the chart type to the OfficeChartType.Column_3D enum value.

C#

//Create and append the chart to the paragraph.
WChart chart = paragraph.AppendChart(446, 270);
//Set chart type.
chart.ChartType = OfficeChartType.Column_3D;
  1. Assign data and chart elements.

Add the basic elements like the chart title, data labels and legend.

  • ChartTitle of the chart object.
  • Set DataLabels.
  • Set TRUE to the chart’s HasLegend property to show the legend, else False.

C#

//Apply the chart elements.
//Set a chart title.
chart.ChartTitle = "Column 3D Chart";
 
//Set legend.
chart.HasLegend = true;
chart.Legend.Position = OfficeLegendPosition.Bottom;
 
//Set Datalabels.
IOfficeChartSerie series1 = chart.Series.Add("Series 1");
series1.Values = chart.ChartData[2, 2, 4, 2];
series1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
  1. Apply 3D chart elements

Add the 3D charts elements like Rotation, Elevation and Perspective.

  • Rotation, Elevation and Perspective of the chart object.

C#

//Set rotation, elevation and perspective.
chart.Rotation = 20;
chart.Elevation = 15;
chart.Perspective = 15;

Applicable properties for 3D column chart

Below is a list of other common properties applicable for 3D column/bar chart.

  • GapWidth (value should be between 0 and 500)
  • GapDepth
  • BarShapeBase and BarShapeTop (to change the shape of the 3D column / bar)
  • PrimarySerieAxis (Depth Axis)
    Note:

    Applying the properties apart from the mentioned list might throw an exception, or the changes will not be reflected in the output document because those properties are not related to the column/bar chart.

The following C# code sample shows the creation of a 3D column chart using the Word library.

C#

//Create a new Word document.
using (WordDocument document = new WordDocument())
{
    // Add a section to the document.
    IWSection section = document.AddSection();
    //Add a paragraph to the section.
    IWParagraph paragraph = section.AddParagraph();
    //Create and append the chart to the paragraph.
    WChart chart = paragraph.AppendChart(446, 270);
    //Set chart type.
    chart.ChartType = OfficeChartType.Column_3D;
    //Assign data.
    AddChartData(chart);
    //Set chart series in the column for assigned data region.
    chart.IsSeriesInRows = false;
    //Set a Chart Title.
    chart.ChartTitle = "Column 3D Chart";
    //Set Datalabels.
    IOfficeChartSerie series1 = chart.Series.Add("Series 1");
    //Set the data range of chart series – start row, start column, end row, and end column.
    series1.Values = chart.ChartData[2, 2, 4, 2];
    IOfficeChartSerie series2 = chart.Series.Add("Series 2");
    //Set the data range of chart series start row, start column, end row, and end column.
    series2.Values = chart.ChartData[2, 3, 4, 3];
    IOfficeChartSerie series3 = chart.Series.Add("Series 3");
    //Set the data range of chart series start row, start column, end row, and end column.
    series3.Values = chart.ChartData[2, 4, 4, 4];
    //Set the data range of the category axis.
    chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 4, 1];
 
    series1.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
    series2.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
    series3.DataPoints.DefaultDataPoint.DataLabels.IsValue = true;
 
    //Set legend.
    chart.HasLegend = true;
    chart.Legend.Position = OfficeLegendPosition.Bottom;
    //Set rotation, elevation and perspective values.
    chart.Rotation = 20;
    chart.Elevation = 15;
    chart.Perspective = 15;
 
    //Create a file stream.
    using (FileStream outputFileStream = new FileStream(Path.GetFullPath(@"../../../Sample.docx"), FileMode.Create, FileAccess.ReadWrite))
    {
           //Save the Word document to the file stream.
           document.Save(outputFileStream, FormatType.Docx);
    }
}

Helper method to set values of the chart in the Word document.

C#

/// <summary>
/// Set the values for the chart.
/// </summary>
private static void AddChartData(WChart chart)
{
    //Set the value for chart data.
    chart.ChartData.SetValue(1, 2, "Series1");
    chart.ChartData.SetValue(1, 3, "Series2");
    chart.ChartData.SetValue(1, 4, "Series3");
 
    chart.ChartData.SetValue(2, 1, "Category1");
    chart.ChartData.SetValue(2, 2, 5);
    chart.ChartData.SetValue(2, 3, 4);
    chart.ChartData.SetValue(2, 4, 3);
 
    chart.ChartData.SetValue(3, 1, "Category2");
    chart.ChartData.SetValue(3, 2, 4);
    chart.ChartData.SetValue(3, 3, 5);
    chart.ChartData.SetValue(3, 4, 2);
 
    chart.ChartData.SetValue(4, 1, "Category3");
    chart.ChartData.SetValue(4, 2, 4);
    chart.ChartData.SetValue(4, 3, 4);
    chart.ChartData.SetValue(4, 4, 3);
}

A complete working sample of how to create 3D column chart in Word document in C# can be downloaded from GitHub.

Take a moment to peruse the documentation, where you can find basic Word document processing options along with the features like mail mergemerge and split documents, find and replace text in the Word document, protect the Word documents, and most importantly, the PDF and Image conversions with code examples.

Explore more about the rich set of Syncfusion Word Framework features and an online example to create a chart in a Word document.

See Also:

How to create clustered column chart in Word document using C# and VB.NET

How to create 3D clustered column chart in Word document using C#?

How to create 100% stacked column chart in Word document using C#?

How to create 3D 100% stacked column chart in Word document using C#?

How to create 3D stacked column chart in Word document using C#?

How to create stacked column chart in Word document using C#?

Conclusion

I hope you enjoyed learning about how to create 3D column chart in Word document using C#.

You can refer to our .NET Core Word library’s feature tour page to know about its other groundbreaking feature representations. You can also explore our .NET Core Word library example to understand how to present and manipulate data. 

For current customers, you can check out our .NET Core components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our .NET Core Word library and other .NET Core components.

If you have any queries or require clarifications, please let us know in comments below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied