improve generate chart image method