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

Area Chart Showing Age Distribution of Customers

Time to Complete: 5 minutes

In the final chart of the dashboard, highlight some of the customer analytic information available in the schema using an area chart. By visualizing the age range and distribution of store customers, you can ensure that any advertising the store performs is directed where it will be seen by the most potential buyers.

Construct the Chart

1

At the top-right corner of the dashboard, click Add Chart.

2

In the Data Source dropdown, select test.supplySales.

3

Select the Chart Type

  1. In the Chart Type dropdown, select Area.
  2. Click Discrete below the dropdown.

Area Chart

An area chart is a good choice to easily visualize the ages where customers are the most concentrated. Since you are not concerned with exact values in this scenario but rather general trends, an area chart makes more sense than a line chart because the filled-in visualization allows us to more easily identify the most common age ranges.

We use a discrete area chart, rather than continuous, because we are ultimately looking for a count of the customers in each particular age bracket determined by the chart’s bin size. Discrete charts allow us to perform aggregation operations on the data, whereas in a continuous chart each data point must come from a distinct document.

4

Add the desired fields to the proper encoding channels.

  1. In the Fields section click the customer field to expand the customer object and view its properties.

  2. Drag the customer.age field to the X Axis encoding channel. The X Axis encoding channel dictates which field to display on the horizontal axis.

  3. Set the Bin Size to 5.

    Data Binning

    Binning data groups continuous data into bins of a specified size. In this case, rather than plotting points for each individual age in the dataset, the data is grouped into bins of 5 ages. This provides a clearer look into the overall trend of the age distribution.

    For more information on data binning, see the Data Binning section.

  4. Drag the _id field to the Y Axis encoding channel. The Y Axis encoding channel determines which field to use for the chart’s aggregation.

    Y Axis Encoding Channel

    Because we will be performing a $count aggregation on the documents, it does not matter what field we use for this encoding channel because the chosen field does not affect the number of documents in each bin.

  5. In the Y Axis Aggregate dropdown, select count. This option counts the occurrence of each customer age from each sale and adds it to the visualization after placing it in the appropriate bin.

Your chart should now look something like this:

Area Chart Builder

In general, customers appear to most commonly between the ages 40-45. This is where the largest area region in the chart occurs. Additionally, the rest of the ages appear to be normally distributed, meaning the average customer age is at the center of the area chart and there are the same number of younger and older customers. You can use this information to direct advertising where the largest customer age group is most likely to see company advertisements.

5

Title your chart.

  1. Hover over your chart title and click the pencil icon.

  2. Copy the following into the title input:

    Distribution of Customer Ages
    
  3. Click the green check mark to save your title.

6

Click Save and Close at the top-left of the chart builder view.

After adding the last chart to your dashboard and performing some final reorganizing, the finished dashboard should look something like this:

Finished Tutorial Dashboard

Wrapping Up

You now have an effective orders dashboard which provides easily accessible insight into revenue data, sales details, and customer analytics. However, with the information you have available in your dataset, there are several ways in which you might be able to add additional charts and extend the dashboard even further. You may want to depict:

  • Average customer satisfaction by store location
  • The amount of money that customers in various age groups typically spend on a purchase
  • Which items are most commonly bought in bulk, utilizing the items.quantity field

Try adding some of these additional charts to the dashboard and see what other interesting correlations between variables you can discover.