Documents for Excel .NET Edition | GCDocuments
Features / Chart / Chart Types / Statistical Chart / Histogram
In This Topic
    In This Topic

    Histograms are visual representation of data distribution over a continuous interval or certain time period. These charts comprise vertical bars to indicate the frequency in each interval or bin created by dividing the raw data values into a series of consecutive and non-overlapping intervals. Hence, histograms help in estimating the range where maximum values fall as well as in knowing the extremes and gaps in data values, if there are any. For instance, histogram can help you find the range of height in which maximum students of a particular age group fall.

    Using Code

    Refer to the following code to add a Histogram chart.

    Copy Code
        public void HistogramChart()
            // Initialize workbook
            Workbook workbook = new Workbook();
            // Fetch default worksheet 
            IWorksheet worksheet = workbook.Worksheets[0];
            // Prepare data for chart
            worksheet.Range["A1:B11"].Value = new object[,]
        {"Complaint", "Count"},
        {"Too noisy", 27},
        {"Overpriced", 789},
        {"Food is tasteless", 65},
        {"Food is not fresh", 19},
        {"Food is too salty", 15},
        {"Not clean", 30},
        {"Unfriendly staff", 12},
        {"Wait time", 109},
        { "No atmosphere", 45},
        {"Small portions", 621 }
            // Add Histogram Chart
            IShape histogramchartShape = worksheet.Shapes.AddChart(ChartType.Histogram, 300, 30, 300, 250);
            // Set range"A1:B11" as the histogram chart series
            // Sets bins type by category
            histogramchartShape.Chart.ChartGroups[0].BinsType = BinsType.BinsTypeCategorical;
            // Configure Chart Title 
            histogramchartShape.Chart.ChartTitle.Text = "Histogram Chart";
            // Saving workbook to Xlsx
            workbook.Save(@"29-HistogramChart.xlsx", SaveFileFormat.Xlsx);