In this example we use an InputField to allow users to enter a Top n Rank value of their choosing.
Error handling has been included in the script to allow users to enter a blank value in the InputField

Script – placed in the onChange event of the InputField
Chart_2.removeRanking();
var Value = this.getValue();
if(Value.length>0) // only retrieve the value from the input field and apply a ranking if a value has been entered
{ var RANK = ConvertUtils.stringToInteger(this.getValue());
Chart_2.rankBy({structureMember:"[Account].[parentId].&[Quantity_sold]",rankOrder:RankOrder.Top,value:RANK});
}
Code language: JavaScript (javascript)
