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

Grouped Column Chart Showing Most Common Items Sold by Store Location

Time to Complete: 5 minutes

By visualizing which items are sold most commonly at each store, you can help ensure each store is properly stocked with the items they are most likely to sell out of. A grouped column chart creates a group within the chart for each store location and display columns within each group reflecting the relative sales of each item.

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 Column.
  2. Click Grouped below the dropdown.
4

Add the desired fields to the proper encoding channels.

  1. Drag the storeLocation field to the X Axis encoding channel. The X Axis encoding channel dictates which field to use when creating the column groups.

    X Axis Encoding Channel

    Using storeLocation for this encoding channel allows us to visualize a group of items per store location.

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

  3. Drag the items.name 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

    Using items.name for this encoding channel allows us to aggregate and count the items sold in each location.

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

    Unwind Array

    The unwind array option creates a new document for each element in the items array, so for each item sold by a particular store that item’s name is added to the visualization.

  5. In the Aggregate dropdown, select count.

    Count

    The count option counts the occurrences of each item name after unwinding the items array and displays them in the chart grouped by store location.

    For more information on the $count aggregation command, refer to the count aggregation documentation.

  6. Drag the items.name field to the Series encoding channel.

    Series Encoding Channel

    The Series encoding channel dictates how to split each group of the chart. Each member of the series becomes a column within the group, so each item name becomes a column within the store location group.

  7. In the Series Array Reductions dropdown, select Unwind array.

    Unwind Array

    This visualizes each tag from each element of the items array, enabling a complete count of the tags from every sale in the data set.

Your chart should now look something like this:

Grouped Column Chart Builder

The item sales look to be fairly evenly distributed by store location. Notice based on this chart that notepads are the most common item sold at all store locations, which is useful information when stocking each store with its inventory.

5

Title your chart.

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

  2. Copy the following into the title input:

    Most Common Items Sold 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.

Your dashboard should now look something like this:

Order Tutorial Dashboard Stage 3

Next Steps

Now that we have a few charts the dashboard is starting to get a bit crowded. Follow along to the next section of the tutorial to see how we can rearrange and resize the charts to make the dashboard easier to digest.