Articles in this section
Category / Section

How to create PowerPoint histogram chart in WinForms Presentation?

3 mins read

This article explains how to create a histogram chart in PowerPoint using Presentation.

 

What is a histogram chart?

 

Histogram shows the frequencies within a distribution. Each column of the chart is called a bin, which can be changed further to analyze the data.

 

Create Histogram Chart in Excel

             Histogram chart created using Presentation

To create a histogram chart in PowerPoint using Presentation, you need to do the following steps.

 

Steps to create histogram chart

 

  1. Initialize chart

 

Create a chart object by calling the slide.Charts.AddChart method and specify the chart type to OfficeChartType.Histogram enum value.

 

            //Create the chart
            IPresentationChart chart = slide.Charts.AddChart(50, 50, 500, 400);
 
            //Set chart type to Histogram
            chart.ChartType = OfficeChartType.Histogram;

 

  1. Assign data

 

Set a range of data from the chartData value to chart’s DataRange property. To plot the series values in column and categories in row, set chart’s IsSeriesInRows property to false.

 

            //Set region of Chart data
            chart.DataRange = chart.ChartData[2, 1, 15, 1];
 
            //Set chart series in column for assigned data region
            chart.IsSeriesInRows = false;

 

  1. Apply basic chart elements

 

Add the basic elements like chart title, data labels and legend with the below list of properties.

 

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

 

              //Apply chart elements
              //Set Chart Title and axis title, category axis bin settings
              chart.ChartTitle = "Histogram Chart";
              chart.PrimaryValueAxis.Title = "Number of students";
              chart.PrimaryCategoryAxis.Title = "Height";
              chart.PrimaryCategoryAxis.BinWidth = 8;
 
              //Set Legend
              chart.HasLegend = false;
              
              //Set Datalabels
              IOfficeChartSerie serie = chart.Series[0];
              serie.SerieFormat.CommonSerieOptions.GapWidth = 6;
                                                                                       

 

Applicable properties of histogram chart

 

Below is the list of other properties that is applicable for a histogram chart.

 

 

Note:

1)Applying other properties unrelated to this chart might throw exception or the changes will not be reflected in the output document because those properties are not related to histogram chart.

2)As histogram chart is introduced in MS PowerPoint 2016, it can’t be viewed in MS PowerPoint 2013 and its earlier versions.

 

 

Download Complete Sample

 

To know more about creating charts with various settings using Presentation, please refer the documentation.

 

The following C#/ VB.NET complete code snippet shows the creation of histogram chart using Presentation.

 

C#

 

using Syncfusion.Presentation;
using Syncfusion.OfficeChart;
using System.IO;
 
namespace ChartSample
{
    class Program
    {
        static void Main(string[] args)
        {
            using (IPresentation pptxDoc= Presentation.Create())
            { 
                // Adds a blank slide to the Presentation
                ISlide slide1 = pptxDoc.Slides.Add(SlideLayoutType.Blank);
 
                // Adds chart to the slide with position and size                
                IPresentationChart chart = slide1.Charts.AddChart(50, 50, 500, 400);
                chart.ChartType = OfficeChartType.Histogram;
 
                //Assign data
                chart.DataRange = chart.ChartData[2, 1, 15, 1];
                chart.IsSeriesInRows = false;
                chart.PrimaryCategoryAxis.BinWidth = 8;
 
                chart.ChartData.SetValue(1, 1, "Student Heights");
                chart.ChartData.SetValue(2, 1, 130);
                chart.ChartData.SetValue(3, 1, 132);
                chart.ChartData.SetValue(4, 1, 159);
                chart.ChartData.SetValue(5, 1, 163);
                chart.ChartData.SetValue(6, 1, 140);
                chart.ChartData.SetValue(7, 1, 155);
                chart.ChartData.SetValue(8, 1, 139);
                chart.ChartData.SetValue(9, 1, 143);
                chart.ChartData.SetValue(10, 1, 153);
                chart.ChartData.SetValue(11, 1, 165);
                chart.ChartData.SetValue(12, 1, 153);
                chart.ChartData.SetValue(13, 1, 149);
                chart.ChartData.SetValue(14, 1, 154);
                chart.ChartData.SetValue(15, 1, 162);
 
                //Apply chart elements
                //Set Chart Title
                chart.ChartTitle = "Histogram Chart";
 
                //Set Datalabels
                IOfficeChartSerie serie1 = chart.Series[0];
                serie1.SerieFormat.CommonSerieOptions.GapWidth = 6;
 
                //Set Legend
                chart.HasLegend = false;
 
                // Set the chart title and axis title
                chart.ChartTitle = “Height Data”;
                chart.PrimaryValueAxis.Title = ”Number of students”;
                chart.PrimaryCategoryAxis.Title = ”Height”; 
 
                //Saving and closing the presentation
                pptxDoc.Save("Histogram.pptx");
                pptxDoc.Close();
            }
        }
    }
}
 

 

VB

Imports Syncfusion.Presentation
Imports Syncfusion.OfficeChart
Imports System.IO
 
Namespace ChartSample
 
    Class Program
 
        Public Shared Sub Main(ByVal args As String())
            'Creates a PowerPoint instance
            Dim pptxDoc As IPresentation = Presentation.Create()            
            Dim slide1 As ISlide = pptxDoc.Slides.Add(SlideLayoutType.Blank)
 
            'Initialize chart
            Dim chart As IPresentationChart = slide1.Charts.AddChart(50, 50, 500, 400)
            chart.ChartType = OfficeChartType.Histogram
 
            'Assign data
            chart.DataRange = chart.ChartData(2, 1, 15, 1)
            chart.IsSeriesInRows = False
            chart.PrimaryCategoryAxis.BinWidth = 8
 
            chart.ChartData.SetValue(1, 1, "Student Heights")
            chart.ChartData.SetValue(2, 1, 130)
            chart.ChartData.SetValue(3, 1, 132)
            chart.ChartData.SetValue(4, 1, 159)
            chart.ChartData.SetValue(5, 1, 163)
            chart.ChartData.SetValue(6, 1, 140)
            chart.ChartData.SetValue(7, 1, 155)
            chart.ChartData.SetValue(8, 1, 139)
            chart.ChartData.SetValue(9, 1, 143)
            chart.ChartData.SetValue(10, 1, 153)
            chart.ChartData.SetValue(11, 1, 165)
            chart.ChartData.SetValue(12, 1, 153)
            chart.ChartData.SetValue(13, 1, 149)
            chart.ChartData.SetValue(14, 1, 154)
            chart.ChartData.SetValue(15, 1, 162)            
 
            'Apply chart elements
            'Set Chart Title
            chart.ChartTitle = "Histogram Chart"
            'Set Datalabels
            Dim serie1 As IOfficeChartSerie = chart.Series(0)            
            serie1.SerieFormat.CommonSerieOptions.GapWidth = 6
 
            'Set Legend
            chart.HasLegend = False
 
            ' Set the chart title and axis title
            chart.ChartTitle = “Height Data”;
            chart.PrimaryValueAxis.Title = ”Number of students”;
            chart.PrimaryCategoryAxis.Title = ”Height”; 
 
            'Saving and closing the presentation
            pptxDoc.Save("Histogram.pptx");
            pptxDoc.Close();
        End Sub
    End Class
End Namespace
 

 

Conclusion

I hope you enjoyed learning about how to create PowerPoint histogram chart in WinForms Presentation.

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 Powerpoint 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 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