sorted chart math
refactored templete
refactored chart percentage math to templete.php