MongoDB Charts supports building multi-series charts, which split your chart data into groups, or series, to compare additional fields within your schema. There are two ways to create multi-series charts:
- Using multiple aggregation or value field mappings. Use this method to compare or aggregate upon multiple non-categorical fields in the schema.
- Using the Series field in the chart builder. Use this method when grouping data based on a discrete list of items.
Multiple Field Mappings to a Single Axis¶
MongoDB Charts allows you to map multiple Aggregation or Value encoding channels to a single chart property (e.g. X Axis or Y Axis). This allows you to compare additional fields in your visualization by creating new series based on the encoding channels added.
After dragging a field to an aggregation or value encoding channel, an additional optional encoding channel of the same type appears below the one which was just added, allowing you to add additional series to your visualization. This process repeats with each channel you add, so you can map as many fields as desired to your chart.
There are two aggregation encoding channels on the chart's Y Axis, one for each of the site's rating fields. By selecting the mean aggregation option, the chart aggregates these two fields using the $avg operator to provide a comparison of the average of two fields in the same column.
Use multiple field mappings to create a multi-series chart when the values being compared in the visualization come from two or more separate fields in the schema.
In the example above, there is one series for Rotten Tomato ratings and one series for IMDB ratings. Since these are separate fields within the schema, adding multiple aggregation encoding channels to map the data is the best choice to compare the fields.
You can also create multi-series charts by using the Series field in the chart builder. The Series field differs from aggregation encoding channels because it instead utilizes a Category encoding channel instead of a Value or Aggregation channel. When creating a series using the Category encoding channel, each unique value from the data field becomes a series in the visualization.
The following multi-series column chart shows order data from an office supply store, showing the most common items sold by store location:
By using the
item.name in the Series encoding
channel, a series within each location group is added for each
The Series field is useful when you are grouping data based on a discrete list of items. This approach should be used when the values for all series are stored in a single field, with a separate field used to establish the discrete categories.