Rewrite barChart() to an object function.