consolidated the bar chart code