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

Column Chart Showing Total Sales by Store Location

Time to Complete: 5 minutes

Looking at the data fields available in the schema, some of the most valuable information you can relay revolves around revenue. You may want to know how various stores are performing, specifically if there are any stores significantly under or overperforming compared to others.

A column chart works well for this type of visualization because you can easily compare individual store revenue based on the size of each column.

Construct the Chart

1

Click Add My First Chart.

2

In the Data Source dropdown, select test.supplySales.

3

Select the Chart Type

  1. In the Chart Type dropdown, select Column.
  2. Click Stacked below the dropdown.

Column Chart

This chart renders a column for each store location’s revenue. Because there are six different store locations, the chart will contain six columns.

4

Add the desired fields to the proper encoding channels.

  1. Drag the storeLocation property from the Fields section of the Chart Builder view to the X Axis encoding channel. This tells MongoDB Charts to create a column for each storeLocation value in the dataset.

  2. In the Fields section click the items field to expand the items object and view its properties.

    Note

    MongoDB Charts infers the data type of each field and provides symbols to easily determine these data types when building your chart. For example, the calendar icon next to the saleDate field signifies that this field is a timestamp. These symbols can help ensure your chart renders as expected by using proper data types for each encoding channel.

  3. Drag the items.price field to the Y Axis encoding channel. The Y Axis encoding channel determines which field to use for the chart’s aggregation.

    Aggregation

    Aggregation processes data records using a wide variety of methods and returns computed results which may not be available in the original dataset. Because we are interested in the total revenue from each store, we use the items.price field here and will use an aggregation operator which will allow us to add the items.price fields together.

  4. In the Array Reductions dropdown, select Unwind array.

    Unwind array

    Array reductions dictate how to process an array so its elements can be visualized. The unwind array option creates a new document for each element in the array, so each item’s price is added to the total for that store.

    For more information on unwinding arrays, refer to the unwind aggregation documentation.

  5. In the Aggregate dropdown, select sum.

    Sum

    This option adds the prices of all items per store together to display the chart. For more information on the $sum aggregation command, refer to the sum aggregation documentation.

Your chart should now look something like this:

Stacked Bar Chart Builder

Notice that the stores generating the most revenue are the Denver and Seattle locations.

5

Title your chart.

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

  2. Copy the following into the chart title input:

    Total Sales ($) by Store Location
    
  3. Click the green check mark to save your title.

6

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

You will be navigated back to your Super Store Supply Sales dashboard and it should look something like this:

Order Tutorial Dashboard Stage 1

Next Steps

Now that we have a visualization showing a high-level overview of store revenue, one might wonder which type of item each store is selling the most of. The following section of the tutorial illustrates how to build a donut chart to analyze the tag names of items being sold.