added $field variable to chart function