This documentation refers to the on-premises edition of MongoDB Charts beta. Read the Atlas service documentation to learn how to use MongoDB Charts beta with your Atlas project.

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 data categories by their corresponding aggregated values in descending order. To toggle between ascending or descending sort order, click the button to the right of the Sort By dropdown. The direction of the arrow on the button indicates the sort direction.

Alternatively, you can sort your data categories in alphabetical order by selecting Category in the Sort By dropdown menu. Changing your selection in the dropdown menu does not affect the sort direction.

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.


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 Customize Charts  →