de-duplicated code in draw_chart