How to create a doughnut chart in Presentation document in WinForms?
The PowerPoint framework is a feature rich .NET PowerPoint
library that can be
used by developers to create, read, edit and convert PowerPoint files to PDFs
and images programmatically without Office or interop dependencies. Using this
library, you can create a doughnut
chart in Presentation document
Steps to create a doughnut chart in Presentation document using C# and VB.NET:
- Create a new C# console application project.
2. Install the Syncfusion.Presentation.WinForms NuGet package as a reference to your .NET Framework applications from NuGet.org
- Include the following namespace in the Program.cs file.
C#
using Syncfusion.Presentation; using Syncfusion.OfficeChart;
VB
Imports Syncfusion.Presentation Imports Syncfusion.OfficeChart
- Use the following code example to create a doughnut chart in Presentation document.
C#
// Create a Presentation instance. using (IPresentation pptxDoc = Presentation.Create()) { //Add a blank slide to the Presentation. ISlide slide = pptxDoc.Slides.Add(SlideLayoutType.Blank); //Add chart to the slide with position and size. IPresentationChart chart = slide.Charts.AddChart(100, 10, 500, 500); //Set the chart type. chart.ChartType = OfficeChartType.Doughnut; //Set the chart line pattern. chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None; //Set the Chart title. chart.ChartTitle = "Current 963 Schematic Health"; chart.ChartTitleArea.FontName = "Helvetica"; chart.ChartTitleArea.Size = 10; //Set the Chart data. chart.ChartData.SetValue(2, 1, "Good"); chart.ChartData.SetValue(2, 2, 2); chart.ChartData.SetValue(3, 1, "Config errors [Missing graphic]"); chart.ChartData.SetValue(3, 2, 4); chart.ChartData.SetValue(4, 1, "Config errors [Broken GOTO link]"); chart.ChartData.SetValue(4, 2, 8); chart.ChartData.SetValue(5, 1, "Config errors [Orphan points]"); chart.ChartData.SetValue(5, 2, 14); //Create a series for the chart. IOfficeChartSerie pieSeries = chart.Series.Add(""); pieSeries.Values = chart.ChartData[2, 2, 5, 2]; //Set the Chart labels. pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsValue = true; pieSeries.DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.White; //Set the chart legend. chart.Legend.TextArea.FontName = "Helvetica"; chart.Legend.TextArea.Size = 10; chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData[2, 1, 5, 1]; chart.Legend.Position = OfficeLegendPosition.Right; chart.Legend.IncludeInLayout = true; chart.Legend.FrameFormat.Border.AutoFormat = true; chart.Legend.FrameFormat.Border.IsAutoLineColor = true; //Set the chart legend positions. chart.Legend.Layout.ManualLayout.Left = 0.668; chart.Legend.Layout.ManualLayout.Top = 0.355; chart.Legend.Layout.ManualLayout.Height = 0.413; chart.Legend.Layout.ManualLayout.Width = 0.319; chart.Legend.Layout.ManualLayout.LeftMode = LayoutModes.edge; chart.Legend.Layout.ManualLayout.TopMode = LayoutModes.edge; //Set the chart plot area positions. chart.PlotArea.Layout.ManualLayout.Left = 0.122; chart.PlotArea.Layout.ManualLayout.Top = 0.239; chart.PlotArea.Layout.ManualLayout.Height = 0.433; chart.PlotArea.Layout.ManualLayout.Width = 0.417; chart.PlotArea.Layout.ManualLayout.LeftMode = LayoutModes.edge; chart.PlotArea.Layout.ManualLayout.TopMode = LayoutModes.edge; chart.PlotArea.Layout.LayoutTarget = LayoutTargets.inner; //Save the Presentation. pptxDoc.Save("DoughnutChart.pptx"); }
VB
'Create an instance of the IPresentation. Using pptxDoc As IPresentation = Presentation.Create 'Add a blank slide to the Presentation. Dim slide As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank) 'Add chart to the slide with position and size. Dim chart As IPresentationChart = slide.Charts.AddChart(100, 10, 500, 500) 'Set the chart type. chart.ChartType = OfficeChartType.Doughnut 'Set the chart line pattern. chart.ChartArea.Border.LinePattern = OfficeChartLinePattern.None 'Set the Chart title. chart.ChartTitle = "Current 963 Schematic Health" chart.ChartTitleArea.FontName = "Helvetica" chart.ChartTitleArea.Size = 10 'Set the Chart data. chart.ChartData.SetValue(2, 1, "Good") chart.ChartData.SetValue(2, 2, 2) chart.ChartData.SetValue(3, 1, "Config errors [Missing graphic]") chart.ChartData.SetValue(3, 2, 4) chart.ChartData.SetValue(4, 1, "Config errors [Broken GOTO link]") chart.ChartData.SetValue(4, 2, 8) chart.ChartData.SetValue(5, 1, "Config errors [Orphan points]") chart.ChartData.SetValue(5, 2, 14) 'Create a series for the chart. Dim pieSeries As IOfficeChartSerie = chart.Series.Add("") pieSeries.Values = chart.ChartData(2, 2, 5, 2) 'Set the Chart labels. pieSeries.DataPoints.DefaultDataPoint.DataLabels.IsValue = True pieSeries.DataPoints.DefaultDataPoint.DataLabels.Color = OfficeKnownColors.White 'Set the chart legend. chart.Legend.TextArea.FontName = "Helvetica" chart.Legend.TextArea.Size = 10 chart.PrimaryCategoryAxis.CategoryLabels = chart.ChartData(2, 1, 5, 1) chart.Legend.Position = OfficeLegendPosition.Right chart.Legend.IncludeInLayout = True chart.Legend.FrameFormat.Border.AutoFormat = True chart.Legend.FrameFormat.Border.IsAutoLineColor = True 'Set the chart legend positions. chart.Legend.Layout.ManualLayout.Left = 0.668 chart.Legend.Layout.ManualLayout.Top = 0.355 chart.Legend.Layout.ManualLayout.Height = 0.413 chart.Legend.Layout.ManualLayout.Width = 0.319 chart.Legend.Layout.ManualLayout.LeftMode = LayoutModes.edge chart.Legend.Layout.ManualLayout.TopMode = LayoutModes.edge 'Set the chart plot area positions. chart.PlotArea.Layout.ManualLayout.Left = 0.122 chart.PlotArea.Layout.ManualLayout.Top = 0.239 chart.PlotArea.Layout.ManualLayout.Height = 0.433 chart.PlotArea.Layout.ManualLayout.Width = 0.417 chart.PlotArea.Layout.ManualLayout.LeftMode = LayoutModes.edge chart.PlotArea.Layout.ManualLayout.TopMode = LayoutModes.edge chart.PlotArea.Layout.LayoutTarget = LayoutTargets.inner 'Save the Presentation. pptxDoc.Save("DoughnutChart.pptx") End Using
A complete working sample to create a doughnut chart in Presentation document using C# can be downloaded from here.
By executing the program, you will get the PowerPoint document as follows.
Explore more about the rich set of PowerPoint Framework Syncfusion features.
See also:
Working with charts in Presentation
Starting with v16.2.0.x, if you reference Syncfusion assemblies from trial setup or from the NuGet feed, include a license key in your projects. Refer to the link to learn about generating and registering a Syncfusion license key in your application to use the components without a trail message.
Conclusion
I hope you enjoyed learning about how to create a doughnut chart in Presentation document in WinForms.
You can refer to our WinForms Presentation feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WinForms Presentation example to understand how to create and manipulate data.
For current customers, you can check out our 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 other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!