Refactoring for some conditional chart handling