How to Use .NET Histogram Charts to Visualize Data in Your Desktop Apps
Tags: webdev, dotnet, tutorial, devops
Published: 2023-02-27 18:19:42

---
canonical_url: https://www.grapecity.com/blogs/how-to-use-net-histogram-charts-to-visualize-data-in-your-desktop-apps
description: Learn how to use .NET Histogram charts to visualize data in your desktop apps.
---
Histogram and ranged histogram charts (available with [ComponentOne FlexChart](https://www.grapecity.com/en/flexchart/) for WinForms, WPF, UWP, Xamarin, and Blazor) empower you with more flexibility to visualize the distribution and dispersion of statistical data.

This blog will demonstrate how to configure FlexChart to visualize cumulative and ranged histogram data in our .NET Windows Forms application.

*   [What are Histogram Charts?](#what)
*   [Creating a Histogram Chart using FlexChart](#create)

*   [Configuring a Cumulative Histogram](#cumulative)
*   [Configuring a Ranged Histogram](#ranged)
*   [Adding a Gaussian or Normal Curve](#curve)

### <a id="what"></a>What are Histogram Charts?

One of the most common statistical charts, histograms visualize the underlying frequency distribution of a given set of continuous data. You can quickly summarize a large range of values by grouping/splitting the entire data set into defined intervals or classes – commonly known as bins. Each bin contains the number of occurrences of the data in the dataset that are contained within that bin. The bins in a histogram are plotted as a vertical (or horizontal) bar on the chart, with the height of the bar (width when horizontal) representing the frequency of data values falling in that bin. There are no spaces.

![WinForms Bar Chart Histogram](https://files.grapecity.com/gc-website-media/nejiqd1j/histogram00.png?width=500&height=268.1818181818182)

It’s important to note that while a bar chart's bar height represents the actual value of items, in a histogram, it represents the frequency of items that fall in each bin. This is most clearly represented by the X-axis containing the grouped bins.

### <a id="create"></a>Creating a Histogram using FlexChart

ComponentOne FlexChart is a flexible component that can be used to visualize dozens of different types of charts. Most charting libraries support bar charts, but they require you to do the data formatting (summing each bin) separately. FlexChart makes it easy to create a histogram because you can just set the data source, and it will automatically calculate and generate appropriate bins. It will aggregate the data for you.

The steps to create a histogram chart are as follows:

1.  Add FlexChart to your application; it will be named flexChart1
2.  Set the ChartType property to Histogram
3.  Set the DataSource property to your data source. (See more details on [how to data bind](https://www.grapecity.com/componentone/docs/win/online-flexchart/binding.html))
4.  Set the BindingX property to the field that gets displayed on the X axis
5.  Create a HistogramSeries and add it to the FlexChart.Series collection.
6.  On the histogram series object, set the Binding property to the same field name as BindingX - this field will be binned and summed.
7.  On the histogram series object, you can also give it a name for the legend and configure the bin width.

![create a .NET histogram chart WinForms](https://files.grapecity.com/gc-website-media/4zlgl40n/01-winforms_flexchart_histogram_frequency.png?width=500&height=325.79075425790757)

Code Example:

```
    flexChart1.ChartType = ChartType.Histogram;
    flexChart1.DataSource = GetMyData(); // replace with your data set
    flexChart1.BindingX = "X";

    // define histogram series object
     var histogramSeries = new C1.Win.Chart.Histogram()
    {
        Binding = "X",
        Name = "Frequency",
        BinWidth = 0.2,
    };

    // add series to FlexChart
    flexChart1.Series.Add(histogramSeries);
```

#### <a id="cumulative"></a>Configuring a Cumulative Histogram

You can use FlexChart to render a regular or cumulative histogram, in which each bar sums the previous bars. To create a cumulative histogram, you need to set the CumulativeMode property to true. Like many specialized properties, these can be found under the FlexChart Options API.

![Configuring a Cumulative .NET Histogram WinForms](https://files.grapecity.com/gc-website-media/25hhbud1/02-winforms_flexchart_cumulative_histogram.png?width=500&height=325.65470417070804)

```
    flexChart1.Options.HistogramCumulativeMode = true;
```

#### <a id="ranged"></a>Configuring a Ranged Histogram

While the categories in a histogram chart have traditionally been associated with quantitative data only, in some scenarios, a user would want to plot text-based categories in the histogram. For example, ages could be visualized based on categories such as 'Youth', 'Young Adults', 'Adults', 'Middle Aged' and 'Older’. With time, there’s been a steady rise in demand for data visualization tools to provide support for such non-numerical x-axis categorization in histograms.

Along similar lines, we introduced a new chart type – ranged histogram – to FlexChart to give flexibility to developers who need to give support for Excel-like chart types in their applications.

![Configuring a Ranged .NET Histogram Chart WinForms](https://files.grapecity.com/gc-website-media/frqnj1xw/03-winforms_flexchart_ranged_histogram.png?width=500&height=164.811229428848)

The key difference is that you may need to format the data more with a ranged histogram before loading FlexChart. Also, you have to set a different ChartType and series type. The new RangedHistogram series type has new properties that enable unique features for the ranged histogram, including an overflow bin, underflow bin, and bin mode.

*   Overflow Bin - FlexChart will automatically create a bin for values that go higher than you set value
*   Underflow Bin - FlexChart will automatically create a bin for values that are lower than a set value
*   Bin Mode - Determines which binning strategy is used from the options below:

*   Automatic - The default behavior and FlexChart will calculate bins for you
*   Bin Width - Each bin is based on a numerical value range you specify
*   Number of Bins - The data is split into the number of bins you specify.

Code Example:

```
    flexChart1.ChartType = ChartType.RangedHistogram;

    var rangedHistoSeries = new C1.Win.Chart.RangedHistogram()
    {
        Binding = "Age",
        BinWidth = 10,
        BinMode = HistogramBinning.BinWidth,
        OverflowBin = 100,
        UnderflowBin = 0,
    };
    this.flexChart1.Series.Add(rangedHistoSeries);
```

This code creates a ranged histogram similar to the one pictured on the left. Creating a ranged histogram such as the one on the right requires your data set to include the named groups such as “Children” and “Adults”. With your data set formatted and grouped by these values, you will set the BindingX property to a custom field in your data set containing the axis labels.

You can check out the documentation to learn more about the [ranged histogram charts](https://www.grapecity.com/componentone/docs/win/online-flexchart/ranged-histogram.html).

#### <a id="curve"></a>Adding a Gaussian or Normal Curve

Histogram data typically visualizes a group's statistics, and we often compare this to a normal bell curve. A Gaussian curve is a bell-shaped curve, also known as a normal curve, which represents the probability distribution of a continuous random variable. FlexChart supports a built-in normal Gaussian curve that you can display to aid visualization. Just set the NormalCurve.Visible on the histogram series object.

```
    // Create a normal curve or gaussian curve
    histogramSeries.NormalCurve.Visible = true;
```

![Adding a Gaussian or Normal Curve .NET Histogram Chart WinForms](https://files.grapecity.com/gc-website-media/r2mbpgqc/04-winforms_flexchart_histogram_normal_curve.png?width=500&height=328.46003898635473)