Refactoring barchart directive