Refactor data integration code in Chart UI