implementing the number of data layers and legends