added function to sort the bar chart