added legend code, but labels array is not populating properly