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

Sort and Limit Categorical Data

On this page

When adding a string field to a non-series category encoding channel, Charts provides the ability to sort and limit results of your data to achieve the best visualization.

Sort Data

By default, Charts sorts the data based on the category field in ascending order. This displays the values of the category field in alphabetical order.

Alternatively, you can choose to sort the data by the aggregated value of the visualization. To toggle between ascending or descending sort order, click the a-z button to the right of the Sort By dropdown.

Limit Data

You can apply a limit to the category encoding channel to only include a specified number of categories in your visualization. The categories included are the first matching categories based on the sort order specified. Limiting data can be useful when visualizing data with so many categories it becomes difficult to create a meaningful chart.

Example

The following chart shows the average IMDb rating of movies from a particular country:

Movie ratings by country

The dataset contains movies from many different countries, but it would be most interesting to see which countries produce the highest-rated movies. We can accomplish this by applying a limit to only show countries with the 10 highest average ratings for movies.

Switch the Limit Results toggle to On and leave the Show input at the default value of 10. The chart is now much easier to understand, and we have a clear view of the countries with the highest-rated movies:

Movie ratings by country limited
←   Bin Data Sample Mode  →