Limit Chart Results

Try this code instead:

handlers.aggregationSuccess = function(data, logger) {
  findLargest5();

  function findLargest5(){
    // sort descending
    data.groups.sort(function(a,b) {
        if (a.Total < b.Total) { return 1; }
        else if (a.Total == b.Total) { return 0; }
        else { return -1; }
    });
      
    var topFive = new Array();
    for (var i = 0; i < 5; i++)
    {
       topFive.push(data.groups[i]); 
    }
    data.groups = topFive;
   }
  return true;
}

Same as before, but this time replace handlers.aggregationSuccess.
Replace Total with the name of Aggregation field you have.


If this doesn't work for you, we'll need to take a closer look at the configuration of your chart to make sure it works in your case.