Refactoring horizontal bar chart code