refactor barchart with vars for common callback functions