Articles in this section
Category / Section

How to create 3D surface 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 surface chart in Word document in C#.

What is a 3D surface chart?

3-D Surface chart shows a 3-D view of the data, which can be imagined as a rubber sheet stretched over a 3-D Column chart. It is typically used to show relationship between large amount of data that may otherwise be difficult to see. Color bands in a surface chart indicate the difference between values.

3D surface chart in ASP.NET Core DocIo

3D Surface chart in Word document

Steps to create 3D surface chart in Word document:

Step 1: Initialize chart

Create a chart object by calling the paragraph.AppendChart(446,270) method.

C#

//Create and append the chart to the paragraph.
WChart chart = paragraph.AppendChart(446, 270);
Step 2: Assign data, chart type and chart elements

Add the basic elements like the chart title, data labels, legend and specify the chart type to the OfficeChartType.Surface_3D enum value.

  • Assign data.
  • Chart type.
  • ChartTitle of the chart object.
  • Set TRUE to the chart’s HasLegend property to show the legend, else False.
    Note:
    1. To plot the series values in column and categories in row, set chart’s IsSeriesInRows property to false.
    2. Set the data range before specifying the chart type.

     

C#

//Set region of Chart data.
chart.DataRange = chart.ChartData[1, 1, 7, 4];
 
//Set chart type.
chart.ChartType = OfficeChartType.Surface_3D;
 
//Set a chart title.
chart.ChartTitle = "3D Surface Chart";
 
//Set legend.
chart.HasLegend = true;
chart.Legend.Position = OfficeLegendPosition.Bottom;

 

Note:

For creating a 3D surface chart, the series count must be greater than or equal to 2. The series should be set before selecting the chart type.

Step 3: 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 = 20;
chart.Perspective = 20;

Applicable properties for 3D surface chart

Other common property applicable for 3D surface chart.

  • 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 3D surface chart.

The following C# code sample shows the creation of 3D surface 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 data.
    chart.ChartData.SetValue(1, 1, "Course");
    chart.ChartData.SetValue(2, 1, "English");
    chart.ChartData.SetValue(3, 1, "Physics");
    chart.ChartData.SetValue(4, 1, "Maths");
    chart.ChartData.SetValue(5, 1, "History");
    chart.ChartData.SetValue(6, 1, "Language 1");
    chart.ChartData.SetValue(7, 1, "Language 2");
    chart.ChartData.SetValue(1, 2, "SchoolA");
    chart.ChartData.SetValue(2, 2, 63);
    chart.ChartData.SetValue(3, 2, 61);
    chart.ChartData.SetValue(4, 2, 62);
    chart.ChartData.SetValue(5, 2, 46);
    chart.ChartData.SetValue(6, 2, 60);
    chart.ChartData.SetValue(7, 2, 63);
    chart.ChartData.SetValue(1, 3, "SchoolB");
    chart.ChartData.SetValue(2, 3, 53);
    chart.ChartData.SetValue(3, 3, 55);
    chart.ChartData.SetValue(4, 3, 51);
    chart.ChartData.SetValue(5, 3, 53);
    chart.ChartData.SetValue(6, 3, 56);
    chart.ChartData.SetValue(7, 3, 58);
    chart.ChartData.SetValue(1, 4, "SchoolC");
    chart.ChartData.SetValue(2, 4, 45);
    chart.ChartData.SetValue(3, 4, 65);
    chart.ChartData.SetValue(4, 4, 64);
    chart.ChartData.SetValue(5, 4, 66);
    chart.ChartData.SetValue(6, 4, 64);
    chart.ChartData.SetValue(7, 4, 64);
    //Set region of Chart data.
    chart.DataRange = chart.ChartData[1, 1, 7, 4];
    //Set chart type.
    chart.ChartType = OfficeChartType.Surface_3D;
    //Set chart series in the column for assigned data region.
    chart.IsSeriesInRows = false;
    //Set a Chart Title.
    chart.ChartTitle = "3D Surface Chart";
    //Set legend.
    chart.HasLegend = true;
    chart.Legend.Position = OfficeLegendPosition.Bottom;
    //Set elevation, rotation, and perspective.
    chart.Rotation = 20;
    chart.Elevation = 20;
    chart.Perspective = 20;
    //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 surface 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 line chart in Word document using C#?

Conclusion

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

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

For current customers, you can check out ASP.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 ASP.NET Core DocIo and other ASP.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 forumsDirect-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  to leave a comment
Access denied
Access denied