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

Donut Chart Showing Most Common Tags for Items Sold

Time to Complete: 5 minutes

Next we will add a chart where you can quickly see which types of items the company is selling the most of. This information will be helpful for the company marketing team to know how effectively direct advertising.

In this scenario, your manager has expressed interest specifically in items sold from the Denver and New York store locations. Additionally, they have requested to only visualize sales which contain an item costing $1200 or more, in an effort to more closely examine the new line of laptops being sold at these locations and what types of items are being bought with them. You can accomplish this using a filter in your donut chart, as shown in the following procedure.

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 Circular.
  2. Click Donut below the dropdown.

Donut Chart

A donut chart is a good choice for this chart because donut charts show the relationship of parts to a whole. Using this chart type you can easily get an idea of which tags make up the greatest portion of total sales.

4

Add the desired fields to the proper encoding channels.

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

  2. Drag the items.tags field to the Label encoding channel. The Label encoding channel dictates which field to use when dividing the sections of the chart.

  3. In the array reduction dropdown for the items array select Unwind array.

    Unwind Array

    Unwinding the array creates a new document for each element of the items array, so each item from each sale is used in the chart.

  4. In the array reduction dropdowns for the tags select Array element by index. Using this option you can specify which element of the tags array to visualize.

  5. Enter 0 for the Index input to only visualize the first element of the tags array. The first item tag is the most relevant tag to the item, so it should be the main concern in the visualiztion. This is the primary item tag.

    Note

    Selecting an array element by index also ensures the chart does not get overcrowded with less important tags as it would had you chosen to unwind the tags array rather than select a specific element.

  6. Drag the items.tags field to the Arc encoding channel.

    Arc Encoding Channel

    The Arc encoding channel dictates which field to aggregate upon in the chart. Using the items.tags field here, you can select an aggregation option which will provide the number of occurrences of each item tag.

  7. Repeat steps c-e for the Arc encoding channel.

    Note

    When constructing donut charts, most often you will be using the same field for both the Label and Arc encoding channels.

  8. In the Aggregate dropdown, select count. This option counts the occurrences of the first tag of each item and adds them to the chart.

Your chart should now look something like this:

Donut Chart Builder
5

Copy the following filter into the Filters input above the main chart display.

{ storeLocation: { $in: [ "Denver", "New York" ] }, 'items.price': {$gte: 1200} }

This filter specifies that Charts only visualizes item tags from items sold from either the Denver or New York store location where there was an item in the sale costing $1200 or more.

6

Click Apply to the right of the filter.

Your chart should now look something like this:

Edit Chart Add Filter

Notice how the electronics tag now takes a larger slice of the distribution compared to when not using the filter. Based on this chart, notice that office and school are the two most common primary item tags from sales matching the filter.

7

Title your chart.

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

  2. Copy the following into the chart title input:

    Frequency of Item Tags from Sales in Denver and New York with Price Threshold
    
  3. Click the green check mark to save your title.

8

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 2

Next Steps

Now that we have a chart showing the tags of the items sold, it would be helpful to know which specific items are most commonly sold at the various store locations. To do so, refer to the next section to see how to implement a grouped column chart showing the most common items sold by store location.