How to create the PowerPoint 3D surface chart in C# and VB.NET?
This article explains how to create a 3D surface chart in WinForms PowerPoint using Presentation library.
What is a 3D surface chart
3D surface chart shows a 3D view of the data, which can be imagined as a rubber sheet stretched over a 3D 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 created using Presentation library
Steps to create 3D surface chart in PowerPoint using Presentation library:
- Initialize chart
Create a chart object by calling the slide.Charts.AddChart method.
//Create the chart IPresentationChart chart = slide.Charts.AddChart(100, 10, 700, 500);
- Assign data and select chart type
- To plot the series values in column and categories in row, set the chart’s IsSeriesInRows property to false.
- Set a range of data from the worksheet to chart’s DataRange property before specifying the chart type.
- Specify the chart type to OfficeChartType.Surface_3D enum value.
//Set chart series in column for assigned data region chart.IsSeriesInRows = false; //Set region of chart data chart.DataRange = chart.ChartData[1, 1, 7, 4]; //Set chart type to Surface_3D chart.ChartType = OfficeChartType.Surface_3D;
No 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.
- Apply basic chart elements
Add the basic elements like chart title, data labels, and legend.
- ChartTitle of chart object.
- Set TRUE to chart’s HasLegend property, to show the legend.
//Apply chart elements //Set chart title chart.ChartTitle = "3D Surface Chart"; //Set legend chart.HasLegend = true; chart.Legend.Position = OfficeLegendPosition.Bottom;
- Apply 3D chart elements
Add the 3D chart elements like rotation, elevation, and perspective.
- Rotation, elevation, and perspective of chart object.
//Set rotation and elevation chart.Rotation = 20; chart.Elevation = 15; chart.Perspective = 15;
Additional applicable properties of 3D surface chart in Excel
To modify the depth axis of 3D surface chart, use the PrimarySerieAxisPrimarySerieAxis (Depth Axis) property.
To learn more about creating charts with various settings using Presentation library, please refer the documentation.
The following C# and VB.NET complete code snippet shows the creation of 3D surface chart using Presentation library.
C#
using Syncfusion.Presentation; using Syncfusion.OfficeChart; using System.IO; namespace ChartSample { class Program { static void Main(string[] args) { //Create an instance for PowerPoint using (IPresentation pptxDoc = Presentation.Create()) { //Add a blank slide to Presentation ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Adds chart to the slide with position and size IPresentationChart chart = slide.Charts.AddChart(100, 10, 700, 500); chart.IsSeriesInRows = false; //Assign data chart.DataRange = chart.ChartData[1, 1, 7, 4]; //Set data to the chart SetChartData(chart); //Set the chart type chart.ChartType = OfficeChartType.Surface_3D; //Apply chart elements //Set chart title chart.ChartTitle = "3D Surface Chart"; //Set legend chart.HasLegend = true; chart.Legend.Position = OfficeLegendPosition.Bottom; //Set rotation and elevation chart.Rotation = 20; chart.Elevation = 15; chart.Perspective = 15; //Saving and closing the presentation Stream stream = File.Create("Output.pptx"); pptxDoc.Save(stream); } } /// <summary> /// Set the values for the chart /// </summary> /// <param name="chart">Represent the instance of the Presentation chart</param> private static void SetChartData(IPresentationChart chart) { 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); } } }
VB
Imports Syncfusion.Presentation Imports Syncfusion.OfficeChart Imports System.IO Namespace ChartSample Class Program Public Shared Sub Main(ByVal args() As String) 'Create an instance for PowerPoint Dim pptxDoc As IPresentation = Presentation.Create() 'Add a blank slide to Presentation Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank) 'Adds chart to the slide with position and size Dim chart As IPresentationChart = slide.Charts.AddChart(100, 10, 700, 500) chart.IsSeriesInRows = False 'Assign data chart.DataRange = chart.ChartData(1, 1, 7, 4) 'Set data to the chart Program.SetChartData(chart) 'Set the chart type chart.ChartType = OfficeChartType.Surface_3D 'Apply chart elements 'Set chart title chart.ChartTitle = "3D Surface Chart" 'Set legend chart.HasLegend = True chart.Legend.Position = OfficeLegendPosition.Bottom 'Set rotation and elevation chart.Rotation = 20 chart.Elevation = 15 chart.Perspective = 15 'Saving and closing the presentation Dim stream As Stream = File.Create("Output.pptx") pptxDoc.Save(stream) End Sub ''' <summary> ''' Set the values for the chart ''' </summary> ''' <param name="chart">Represent the instance of the Presentation chart</param> Private Shared Sub SetChartData(ByVal chart As IPresentationChart) 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) End Sub End Class End Namespace
Conclusion
Hope you enjoyed learning about how to create the PowerPoint 3D surface chart in C# and VB.NET.
You can refer to our WinForms PowerPoint’s feature tour page to know about its other groundbreaking feature representations. You can explore our WinForms PowerPoint documentation to understand how to present and manipulate data.
For current customers, you can check out our WinForms 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 WinForms PDF and other WinForms 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!