Updated the logic for dynamic charts