# Histogram | WPF Controls | DevExpress Documentation

This topic explains how to customize the Chart Control’s axis and series settings to make a [histogram](https://en.wikipedia.org/wiki/Histogram).

![](/WPF/images/chart-control/histogram-preview.png)

**Required Steps**

- Specify a Data Source
- Aggregate Data and Divide an Axis Scale into Intervals

**Optional Steps**

- Specify Side Bin Thresholds
- Specify Bar Width
- Configure the Grid and Label Layout
- Customize Axis Label Text

## Specify a Data Source

You can provide histogram data to a chart in the following ways:

- Define a data source field that provides series arguments. You do not have to [supply data](/WPF/6854/controls-and-libraries/charts-suite/chart-control/provide-data/provide-data) for series point values. The Chart Control calculates values as aggregates based on the frequency of arguments.
- You can use a one-dimensional array as a data source. In this case, you do not have to specify the argument data member.

You can use the following API:

| Member | Description |
| --- | --- |
| [ChartControl.DataSource](/WPF/DevExpress.Xpf.Charts.ChartControl.DataSource) ([Series.DataSource](/WPF/DevExpress.Xpf.Charts.Series.DataSource)) | Specifies the chart control (series) data source. |
| [Series.ArgumentDataMember](/WPF/DevExpress.Xpf.Charts.Series.ArgumentDataMember) | Gets or sets the name of the data field which contains arguments for generated series points. |

- XAML
- C#
- VB.NET

<section id="tabpanel_fkPzlgQ4J4_tabid-xaml1" role="tabpanel" data-tab="tabid-xaml1">
<pre><code class="lang-xaml">&lt;dxc:ChartControl x:Name=&quot;chartControl&quot;&gt;
    &lt;dxc:ChartControl.Titles&gt;
        &lt;dxc:Title HorizontalAlignment=&quot;Center&quot; 
                   Content=&quot;Temperature Histogram&quot;/&gt;
    &lt;/dxc:ChartControl.Titles&gt;
    &lt;dxc:XYDiagram2D&gt;
        &lt;dxc:BarSideBySideSeries2D  DisplayName=&quot;Histogram&quot; 
                                    DataSource=&quot;{Binding}&quot; 
                                    ArgumentDataMember=&quot;Temperature&quot;&gt;
        &lt;/dxc:BarSideBySideSeries2D&gt;
    &lt;/dxc:XYDiagram2D&gt;
&lt;/dxc:ChartControl&gt;
</code></pre></section>
<section id="tabpanel_fkPzlgQ4J4_tabid-csharp1" role="tabpanel" data-tab="tabid-csharp1" aria-hidden="true" hidden="hidden">
<pre><code class="lang-csharp">public partial class MainWindow : Window {
    public MainWindow() {
        InitializeComponent();
        DataContext = CityDailyWeather.Load();     
    }
    [XmlRoot(&quot;CityDailyWeather&quot;)]
    public class CityDailyWeather : List&lt;WeatherItem&gt; {
        public static CityDailyWeather Load() {
            XmlSerializer serializer = XmlSerializer.FromTypes(new[] { typeof(CityDailyWeather) })[0];
            return (CityDailyWeather)serializer.Deserialize(LoadFromResources(&quot;/Data/CityWeather.xml&quot;));

        }
        public static Stream LoadFromResources(string fileName) {
            try {
                Uri uri = new Uri(fileName, UriKind.RelativeOrAbsolute);
                return Application.GetResourceStream(uri).Stream;
            }
            catch {
                return null;
            }
        }
    }
}
public class WeatherItem {
    public DateTime Date { get; set; }
    public double Temperature { get; set; }
}
</code></pre></section>
<section id="tabpanel_fkPzlgQ4J4_tabid-vb1" role="tabpanel" data-tab="tabid-vb1" aria-hidden="true" hidden="hidden">
<pre><code class="lang-vb">Public Partial Class MainWindow
    Inherits Window
    Public Sub New()
        InitializeComponent()
        DataContext = CityDailyWeather.Load()
    End Sub
    &lt;XmlRoot(&quot;CityDailyWeather&quot;)&gt;
    Public Class CityDailyWeather
        Inherits List(Of WeatherItem)

        Public Shared Function Load() As CityDailyWeather
            Dim serializer As XmlSerializer = XmlSerializer.FromTypes({GetType(CityDailyWeather)})(0)
            Return CType(serializer.Deserialize(LoadFromResources(&quot;/Data/CityWeather.xml&quot;)), CityDailyWeather)
        End Function

        Public Shared Function LoadFromResources(ByVal fileName As String) As Stream
            Try
                Dim uri As Uri = New Uri(fileName, UriKind.RelativeOrAbsolute)
                Return Application.GetResourceStream(uri).Stream
            Catch
                Return Nothing
            End Try
        End Function
    End Class
End Class
Public Class WeatherItem
    Public Property Date As DateTime
    Public Property Temperature As Double
End Class
</code></pre></section>

The data structure looks as follows:

- XML

<section id="tabpanel_fkPzlgQ4J4-1_tabid-xml" role="tabpanel" data-tab="tabid-xml">
<pre><code class="lang-xml">&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;CityDailyWeather xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
                    xmlns:xsd=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
  &lt;xs:schema xmlns:xs=&quot;http://www.w3.org/2001/XMLSchema&quot;&gt;
    &lt;xs:element name=&quot;WeatherItem&quot;&gt;
      &lt;xs:complexType&gt;
        &lt;xs:sequence&gt;
          &lt;xs:element name=&quot;Date&quot; type=&quot;xs:dateTime&quot;/&gt;
          &lt;xs:element name=&quot;Temperature&quot; type=&quot;xs:double&quot;/&gt;
        &lt;/xs:sequence&gt;
      &lt;/xs:complexType&gt;
    &lt;/xs:element&gt;
  &lt;/xs:schema&gt;
  &lt;WeatherItem&gt;
    &lt;Date&gt;2018-01-01T00:00:00&lt;/Date&gt;
    &lt;Temperature&gt;-17.5&lt;/Temperature&gt;
  &lt;/WeatherItem&gt;
  &lt;WeatherItem&gt;
    &lt;Date&gt;2018-01-02T00:00:00&lt;/Date&gt;
    &lt;Temperature&gt;-16.3&lt;/Temperature&gt;
  &lt;/WeatherItem&gt;
  &lt;!--...--&gt;
&lt;/CityDailyWeather&gt;   
</code></pre></section>

## Aggregate Data and Divide an Axis Scale into Bins

### The Number of Bins is Auto-Calculated

The Chart control can apply *Scott’s Normal Reference Rule* to compute an optimal number of bins and their ranges:

- Initialize the [AxisX2D.NumericScaleOptions](/WPF/DevExpress.Xpf.Charts.AxisX2D.NumericScaleOptions) property with a new [IntervalNumericScaleOptions](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions) object. (For date-time axes, use [AxisX2D.DateTimeScaleOptions](/WPF/DevExpress.Xpf.Charts.AxisX2D.DateTimeScaleOptions) and [IntervalDateTimeScaleOptions](/WPF/DevExpress.Xpf.Charts.IntervalDateTimeScaleOptions) instead.)
- Set the [ManualNumericScaleOptions.AggregateFunction](/WPF/DevExpress.Xpf.Charts.ManualNumericScaleOptions.AggregateFunction) property to **Histogram**.

- XAML

<section id="tabpanel_fkPzlgQ4J4-2_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;dxc:XYDiagram2D&gt;
    &lt;dxc:XYDiagram2D.AxisX&gt;
        &lt;dxc:AxisX2D&gt;
            &lt;dxc:AxisX2D.NumericScaleOptions&gt;
                &lt;dxc:IntervalNumericScaleOptions AggregateFunction=&quot;Histogram&quot;/&gt;
            &lt;/dxc:AxisX2D.NumericScaleOptions&gt;
        &lt;/dxc:AxisX2D&gt;
    &lt;/dxc:XYDiagram2D.AxisX&gt;
    &lt;!-- Series settings are skipped. --&gt;
&lt;/dxc:XYDiagram2D&gt;
</code></pre></section>

### Specify the Number of Bins

The Chart Control can display a specified number of bins for [numeric](/WPF/115179/controls-and-libraries/charts-suite/chart-control/axes/axis-scale-types#numerical) axes. The bin value range is calculated automatically.

![](/WPF/images/chart-control/histogram-count-5.png)

The following code creates a histogram with five bins:

- XAML

<section id="tabpanel_fkPzlgQ4J4-3_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;dxc:XYDiagram2D&gt;
    &lt;dxc:XYDiagram2D.AxisX&gt;
        &lt;dxc:AxisX2D TickmarksMinorVisible=&quot;False&quot; 
                     GridLinesVisible=&quot;True&quot;&gt;
            &lt;dxc:AxisX2D.NumericScaleOptions&gt;
                &lt;!-- Configure a histogram with the specified number of bins. --&gt;
                &lt;dxc:CountIntervalNumericScaleOptions AggregateFunction=&quot;Histogram&quot;
                                                      Count=&quot;5&quot;/&gt;
            &lt;/dxc:AxisX2D.NumericScaleOptions&gt;
        &lt;/dxc:AxisX2D&gt;
    &lt;/dxc:XYDiagram2D.AxisX&gt;
&lt;/dxc:XYDiagram2D&gt;        
</code></pre></section>

The following table lists the API members used in the code above:

| Member | Description |
| --- | --- |
| [CountIntervalNumericScaleOptions](/WPF/DevExpress.Xpf.Charts.CountIntervalNumericScaleOptions) | These options provide the **Count** property. Use this property to specify the number of bins. |
| [CountIntervalNumericScaleOptions.Count](/WPF/DevExpress.Xpf.Charts.CountIntervalNumericScaleOptions.Count) | Gets or sets the number of intervals. |

### Specify the Bin Size

You can specify the bin size (measured in x-axis units). The number of bins is calculated automatically.

![](/WPF/images/chart-control/histogram-width-10.png)

The code below creates bins with a size equal to ten x-axis measurement units:

- XAML

<section id="tabpanel_fkPzlgQ4J4-4_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;dxc:XYDiagram2D&gt;
    &lt;dxc:XYDiagram2D.AxisX&gt;
        &lt;dxc:AxisX2D TickmarksMinorVisible=&quot;False&quot; 
                     GridLinesVisible=&quot;True&quot;&gt;
            &lt;dxc:AxisX2D.NumericScaleOptions&gt;
                &lt;!-- Configure a histogram with bins of specified width. --&gt;
                &lt;dxc:WidthIntervalNumericScaleOptions AggregateFunction=&quot;Histogram&quot;
                                                      Width=&quot;10&quot;/&gt;
            &lt;/dxc:AxisX2D.NumericScaleOptions&gt;
        &lt;/dxc:AxisX2D&gt;
    &lt;/dxc:XYDiagram2D.AxisX&gt;
&lt;/dxc:XYDiagram2D&gt;        
</code></pre></section>

The following table lists the API members used in the code above:

| Member | Description |
| --- | --- |
| [WidthIntervalNumericScaleOptions](/WPF/DevExpress.Xpf.Charts.WidthIntervalNumericScaleOptions) | The options that provide means to create axis intervals with a specified width. |
| [WidthIntervalNumericScaleOptions.Count](/WPF/DevExpress.Xpf.Charts.WidthIntervalNumericScaleOptions.Width) | Gets or sets the interval width in x-axis measurement units. |

## Specify Side Bin Thresholds

You can change thresholds for underflow and overflow bins:

![](/WPF/images/chart-control/histogram-underflow-overflow-values.png)

The following code uses the [IntervalNumericScaleOptions.UnderflowValue](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions.UnderflowValue) and [IntervalNumericScaleOptions.OverflowValue](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions.OverflowValue) properties to change thresholds. (For date-time axes, use [IntervalDateTimeScaleOptions.UnderflowValue](/WPF/DevExpress.Xpf.Charts.IntervalDateTimeScaleOptions.UnderflowValue) and [IntervalDateTimeScaleOptions.OverflowValue](/WPF/DevExpress.Xpf.Charts.IntervalDateTimeScaleOptions.OverflowValue) instead.)

- XAML

<section id="tabpanel_fkPzlgQ4J4-5_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;dxc:XYDiagram2D&gt;
    &lt;dxc:XYDiagram2D.AxisX&gt;
        &lt;dxc:AxisX2D TickmarksMinorVisible=&quot;False&quot; 
                     GridLinesVisible=&quot;True&quot;&gt;
            &lt;dxc:AxisX2D.NumericScaleOptions&gt;
                &lt;dxc:IntervalNumericScaleOptions AggregateFunction=&quot;Histogram&quot;       
                                                 UnderflowValue=&quot;-20&quot;
                                                 OverflowValue=&quot;15&quot;/&gt;
            &lt;/dxc:AxisX2D.NumericScaleOptions&gt;
        &lt;/dxc:AxisX2D&gt;                                     
    &lt;/dxc:XYDiagram2D.AxisX&gt;
&lt;/dxc:XYDiagram2D&gt;    
</code></pre></section>

## Specify Bar Width

A histogram can use [bars](/WindowsForms/2972/controls-and-libraries/chart-control/series-views/2d-series-views/bar-series-views/side-by-side-bar-chart) positioned next to each other without gaps to display histogram bins. 

![](/WPF/images/chart-control/histogram-bar-width.png)

Set the [BarSeries2DBase.BarWidth](/WPF/DevExpress.Xpf.Charts.BarSeries2DBase.BarWidth) property to **1** to remove gaps between bars.

- XAML

<section id="tabpanel_fkPzlgQ4J4-6_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;dxc:XYDiagram2D&gt;
    &lt;dxc:BarSideBySideSeries2D  DisplayName=&quot;Histogram&quot; 
                                DataSource=&quot;{Binding}&quot; 
                                ArgumentDataMember=&quot;Temperature&quot; 
                                BarWidth=&quot;1&quot;&gt;
    &lt;/dxc:BarSideBySideSeries2D&gt;
    &lt;dxc:XYDiagram2D.AxisX&gt;
        &lt;dxc:AxisX2D TickmarksMinorVisible=&quot;False&quot; 
                     GridLinesVisible=&quot;True&quot;&gt;
            &lt;dxc:AxisX2D.NumericScaleOptions&gt;
                &lt;dxc:IntervalNumericScaleOptions AggregateFunction=&quot;Histogram&quot; 
                                                 UnderflowValue=&quot;-20&quot;
                                                 OverflowValue=&quot;15&quot;/&gt;
            &lt;/dxc:AxisX2D.NumericScaleOptions&gt;
            &lt;dxc:AxisX2D.WholeRange&gt;
                &lt;dxc:Range SideMarginsValue=&quot;0.8&quot;/&gt;
            &lt;/dxc:AxisX2D.WholeRange&gt;
        &lt;/dxc:AxisX2D&gt;
    &lt;/dxc:XYDiagram2D.AxisX&gt;
&lt;/dxc:XYDiagram2D&gt;
</code></pre></section>

## Configure the Grid and Label Layout

The Chart Control aligns [axis labels](/WPF/6336/controls-and-libraries/charts-suite/chart-control/axes/axis-labels), major [grid lines](/WPF/6337/controls-and-libraries/charts-suite/chart-control/axes/tickmarks-grid-lines-and-interlacing), and major [tick marks](/WPF/6337/controls-and-libraries/charts-suite/chart-control/axes/tickmarks-grid-lines-and-interlacing) to the center of each bin. You can also align them to the start of each interval.

![](/WPF/images/chart-control/histogram-grid-and-label-alignment.png)

Specify the **GridLayoutMode** ([IntervalNumericScaleOptions.GridLayoutMode](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions.GridLayoutMode), [DateTimeScaleOptionsBase.GridLayoutMode](/WPF/DevExpress.Xpf.Charts.DateTimeScaleOptionsBase.GridLayoutMode) or [QualitativeScaleOptions.GridLayoutMode](/WPF/DevExpress.Xpf.Charts.QualitativeScaleOptions.GridLayoutMode)) property to change the axis label, grid line, or tick mark alignment.

- XAML

<section id="tabpanel_fkPzlgQ4J4-7_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;dxc:XYDiagram2D&gt;
    &lt;dxc:XYDiagram2D.AxisX&gt;
        &lt;dxc:AxisX2D TickmarksMinorVisible=&quot;False&quot; 
                     GridLinesVisible=&quot;True&quot;&gt;
            &lt;dxc:AxisX2D.NumericScaleOptions&gt;
                &lt;dxc:IntervalNumericScaleOptions AggregateFunction=&quot;Histogram&quot;
                                                 GridLayoutMode=&quot;GridAndLabelShifted&quot;
                                                 UnderflowValue=&quot;-20&quot;
                                                 OverflowValue=&quot;15&quot;/&gt;
            &lt;/dxc:AxisX2D.NumericScaleOptions&gt;
            &lt;dxc:AxisX2D.Label&gt;
                &lt;dxc:AxisLabel TextPattern=&quot;{}{A:F0}°C&quot;/&gt;
            &lt;/dxc:AxisX2D.Label&gt;
        &lt;/dxc:AxisX2D&gt;
    &lt;/dxc:XYDiagram2D.AxisX&gt;
&lt;/dxc:XYDiagram2D&gt;
</code></pre></section>

## Customize Axis Label Text

You can format label text for axis scale intervals and the underflow/overflow bins.

![](/WPF/images/chart-control/histogram-text-patterns.png)

- XAML

<section id="tabpanel_fkPzlgQ4J4-8_tabid-xaml" role="tabpanel" data-tab="tabid-xaml">
<pre><code class="lang-xaml">&lt;dxc:XYDiagram2D&gt;
    &lt;dxc:XYDiagram2D.AxisX&gt;
        &lt;dxc:AxisX2D TickmarksMinorVisible=&quot;False&quot; 
                     GridLinesVisible=&quot;True&quot;&gt;
            &lt;dxc:AxisX2D.NumericScaleOptions&gt;
                   &lt;dxc:CountIntervalNumericScaleOptions AggregateFunction=&quot;Histogram&quot;
                                             Pattern=&quot;{}{OB}{A1:F0}°C – {A2:F0}°C{CB}&quot;
                                             UnderflowValuePattern=&quot;{}{US} {A2}°C&quot;
                                             OverflowValuePattern=&quot;{}{OS} {A1}°C&quot;     
                                             GridLayoutMode=&quot;GridShiftedLabelCentered&quot;
                                             UnderflowValue=&quot;-20&quot;
                                             OverflowValue=&quot;15&quot;
                                             Count=&quot;4&quot;/&gt;
            &lt;/dxc:AxisX2D.NumericScaleOptions&gt;
        &lt;/dxc:AxisX2D&gt;
    &lt;/dxc:XYDiagram2D.AxisX&gt;
&lt;/dxc:XYDiagram2D&gt;
</code></pre></section>

The following table lists the API members the code above uses:

| Member | Description |
| --- | --- |
| [IntervalNumericScaleOptions.Pattern](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions.Pattern) | Gets or sets a format string that configures text for the interval [axis labels](/WPF/6336/controls-and-libraries/charts-suite/chart-control/axes/axis-labels) and [crosshair](/WPF/14682/controls-and-libraries/charts-suite/chart-control/tooltip-and-crosshair-cursor/crosshair-cursor) labels. |
| [IntervalNumericScaleOptions.UnderflowValuePattern](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions.UnderflowValuePattern) | Gets or sets a format string that configures text for the underflow interval [axis labels](/WPF/6336/controls-and-libraries/charts-suite/chart-control/axes/axis-labels) and [crosshair](/WPF/14682/controls-and-libraries/charts-suite/chart-control/tooltip-and-crosshair-cursor/crosshair-cursor) labels. |
| [IntervalNumericScaleOptions.OverflowValuePattern](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions.OverflowValuePattern) | Gets or sets a format string that configures text for the overflow interval [axis labels](/WPF/6336/controls-and-libraries/charts-suite/chart-control/axes/axis-labels) and [crosshair](/WPF/14682/controls-and-libraries/charts-suite/chart-control/tooltip-and-crosshair-cursor/crosshair-cursor) labels. |

Patterns can contain regular text (displayed as is) and value placeholders in braces. To format numeric and date/time values, you can apply [Format Specifiers](/WPF/10408/common-concepts/formatting-values/format-specifiers). Use a colon to separate a placeholder and its format specifier. In XAML, insert an escape sequence ({}) into the beginning of a pattern if it starts with a placeholder.

The following table contains the available placeholders:

| Placeholder | Description |
| --- | --- |
| {OB} | Displays an *opening bracket*. |
| {CB} | Displays a *closing bracket*. |
| {OS} | Displays the *greater than* sign. |
| {US} | Displays the *less than* or *less than or equal to* sign. |
| {A1} | Displays the *interval start value*. |
| {A2} | Displays the *interval end value*. |

Note

Use the [AxisLabel.TextPattern](/WPF/DevExpress.Xpf.Charts.AxisLabel.TextPattern) property to format label text when the **GridLayoutMode** ([IntervalNumericScaleOptions.GridLayoutMode](/WPF/DevExpress.Xpf.Charts.IntervalNumericScaleOptions.GridLayoutMode), [DateTimeScaleOptionsBase.GridLayoutMode](/WPF/DevExpress.Xpf.Charts.DateTimeScaleOptionsBase.GridLayoutMode) or [QualitativeScaleOptions.GridLayoutMode](/WPF/DevExpress.Xpf.Charts.QualitativeScaleOptions.GridLayoutMode)) property is set to **GridAndLabelShifted**.

## Examples

- [How to: Plot an XY Series with a Histogram in a Chart](/WPF/403342/controls-and-libraries/charts-suite/chart-control/examples/providing-data/how-to-plot-an-xy-series-with-a-histogram-in-a-chart)