How to create 3D clustered column chart in Word document using C#?
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 clustered column chart in Word document in C#.
What is 3D clustered column chart?
A 3D clustered column chart plots the data in discrete vertical rectangles.
3D Clustered Column chart in Word document
Steps to create 3D clustered column chart in Word document:
- Initialize chart.
Create a chart object by calling the paragraph.AppendChart(446,270) method and specify the chart type to the OfficeChartType.Column_Clustered_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_Clustered_3D;
Add the basic elements like the chart title, and legend.
- Assign data.
- ChartTitle of the chart object.
- Set TRUE to the chart’s HasLegend property to show the legend, else False.
C#
//Set region of Chart data. chart.DataRange = chart.ChartData[1, 1, 6, 4]; //Apply the chart elements. //Set a chart title. chart.ChartTitle = "3D Clustered Column Chart"; //Set legend. chart.HasLegend = true; chart.Legend.Position = OfficeLegendPosition.Bottom;
- Apply 3D chart elements
Add the 3D charts elements like Rotation and Elevation.
- Rotation and Elevation of the chart object.
C#
//Set rotation and elevation. chart.Rotation = 30; chart.Elevation = 30;
Applicable properties for 3D clustered 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)
- IsVaryColorNote:
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 column/bar chart.
The following C# code sample shows the creation of a 3D clustered 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_Clustered_3D; //Set chart data. chart.ChartData.SetValue(1, 1, "Fruits"); chart.ChartData.SetValue(2, 1, "Apples"); chart.ChartData.SetValue(3, 1, "Grapes"); chart.ChartData.SetValue(4, 1, "Bananas"); chart.ChartData.SetValue(5, 1, "Oranges"); chart.ChartData.SetValue(6, 1, "Melons"); chart.ChartData.SetValue(1, 2, "Joey"); chart.ChartData.SetValue(2, 2, 5); chart.ChartData.SetValue(3, 2, 4); chart.ChartData.SetValue(4, 2, 4); chart.ChartData.SetValue(5, 2, 2); chart.ChartData.SetValue(6, 2, 2); chart.ChartData.SetValue(1, 3, "Matthew"); chart.ChartData.SetValue(2, 3, 3); chart.ChartData.SetValue(3, 3, 5); chart.ChartData.SetValue(4, 3, 4); chart.ChartData.SetValue(5, 3, 1); chart.ChartData.SetValue(6, 3, 7); chart.ChartData.SetValue(1, 4, "Peter"); chart.ChartData.SetValue(2, 4, 2); chart.ChartData.SetValue(3, 4, 2); chart.ChartData.SetValue(4, 4, 3); chart.ChartData.SetValue(5, 4, 5); chart.ChartData.SetValue(6, 4, 6); //Set region of Chart data. chart.DataRange = chart.ChartData[1, 1, 6, 4]; //Set chart series in the column for assigned data region. chart.IsSeriesInRows = false; //Set a Chart Title. chart.ChartTitle = "3D Clustered Column Chart"; //Set legend. chart.HasLegend = true; chart.Legend.Position = OfficeLegendPosition.Bottom; //Set rotation and elevation. chart.Rotation = 30; chart.Elevation = 30; //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); } }
A complete working sample of how to create 3D clustered 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 merge, merge 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 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#?