Navigation
This documentation refers to the on premises version of MongoDB Charts. For documentation on the MongoDB Charts SaaS application in Atlas, click here.

Bin Data

MongoDB Charts supports binning both numeric and date fields in your data. Binning breaks continuous data into discrete groups called bins, with each bin containing a contiguous subset of the original values. For example, you might group users into bins by the decade they were born, or group timestamped calendar events by the month of their start date.

Continuous vs Discrete Data

Continuous data can occupy any value over a continuous range. Some examples of continuous data include height, temperature, or the time a person was born.

Alternatively, discrete data is data which can only take certain values, categorized into a classification. Examples of discrete data include eye color and the number of students in a class.

Bin Date Fields

When handling dates, this data often comes in a continuous form. It can be useful to split this data into a specific windows of time to uncover additional trends and patterns. MongoDB Charts supports the following bins for dates:

  • Year
  • Month
  • Date of the Month
  • Day of the Week
  • Hour
  • Minute
  • Second

To use binning for dates:

  1. Drag a date field (signified by a calendar icon in the Fields section of the Chart Builder) to a category encoding channel.

    By default, binning is enabled as indicated by the Binning On toggle.

  2. Use the dropdown to select the bin size for your dates.

  3. Toggle the Periodic setting as desired.

    • If enabled, MongoDB Charts creates bins relative to the next highest time period and repeats each bin to cover the timeframe spanned in the data field.
    • If disabled, the bins Charts creates do not repeat.

    Example

    Consider a date field containing data spanning 5 years, and a bin selection of Month. If Periodic is disabled, Charts adds the 60 months in the dataset to the visualization.

    Alternatively, if Periodic is enabled, Charts only plots the 12 calendar months, and visualizes the total aggregated results from each calendar month.

    Note

    The Periodic setting is always enabled when selecting a bin size of Day of the Week.

    The Periodic setting is always disabled when selecting a bin size of Year, because year is the largest time period available in Charts.

To disable binning, toggle the Binning setting to off. In this case, each date from the field is added to the visualization with no grouping performed.

Example

The following chart visualizes historical sales data for an office supply store. Every sale is represented by a document in the supplySales collection. Each document in the collection includes the date of the sale as salesDate and a list of items included in the sale as the items array.

The saleDate field contains continuous timestamp data. The field is binned by Date of the Month with the Periodic setting enabled. This means that over the course of the several years the data spans, MongoDB Charts plots the mean value of sales from each individual date of the month:

Charts binning by day example

Bin Numeric Fields

MongoDB Charts can also bin numeric fields from a continuous set into groups of a specified size. This

To use binning for numeric fields:

  1. Drag a numeric field (signified by the number sign icon in the Fields section of the Chart Builder) to a category encoding channel.

    By default, binning is enabled as indicated by the toggle stating Binning On.

  2. Enter the desired bin size in the Bin Size input.

To disable binning, toggle the Binning setting to off. In this case, each individual value from the field is added to the visualization, rather than being grouped into bins.

Example

The following chart visualizes historical sales data for an office supply store. Every sale is represented by a document in the supplySales collection. Each sale document contains a customer object, which contains information on the customer purchasing the item(s).

The following chart applies binning to the customer.age field. The age field contains continuous numeric data and is binned by decade. Each age value is placed into the appropriate bin and Charts counts the number of ages in each bin to provide a high-level overview of the age distrubution of store customers.

Charts numeric binning example