modify generate chart image function