adding dynamic legend