refactoring the bar chart