how I can insert labels for the legend dynamically?