Having a variable number of data sets in grouped bar graphs

I am trying to make a script that creates a bar graph, and I would like it to be able have be able to have a variable number of data sets. I tried making a for loop that would append a list that would ultimately make up the data for the graph, but it doesnโ€™t seem to have worked, and says that the data is empty. What to do?