Hi,
I am not sure you can do loop within charts...
I have at least two solutions without loops:
1) just list management
2) put a reflex in the experiment which will update a list variable used in the chart.
Considering your exemple, the first solution is the simplest, but you can't do the multiplications:
Here is an example:
chart "DataListBar" type:histogram style:"3d"
{
datalist legend:["val1","val2"] categoriesnames:(ant collect
each.name) value:[(ant collect each.val1),(ant collect each.val2)] style:stack;
}
(I put the complete exemple bellow just in case it is not clear, and the result image)
You can create your list of list on the fly, for you something like:
datalist value:[(commune collect each.U_0_5c),(commune collect each.U_0_5c),(commune collect each.U_0_5c)] style:stack legend:["A","B","C"] categoriesnames:[(commune collect each.name)];

model new
global {
int ants_number <- 4 min: 1 max: 2000 ;
init{
int a<-1;
create ant number: ants_number{
name<-"ant"+a;
val1<-a;
val2<-a+2;
a<-a+1;
}
}
}
species ant skills: [moving] {
float speed <- 2.0 ;
string name;
int val1<-2;
int val2<-3;
aspect default {
draw shape: circle(1.0) color: #orange ;
}
}
experiment Ant type: gui {
parameter 'Number of ants:' var: ants_number category: 'Model' ;
reflex update_charts
{
}
output {
display ChartHistoList {
chart "DataListBar" type:histogram style:"3d"
{
datalist legend:["val1","val2"] categoriesnames:(ant collect
each.name) value:[(ant collect each.val1),(ant collect each.val2)] style:stack;
}
}
}
}
2) If you want the multiplications, you can use a list variable:
(in this case you can put your loop in the reflex)
experiment Ant type: gui {
parameter 'Number of ants:' var: ants_number category: 'Model' ;
list<list<int>> myvalues<-[[1,2],[3,4]];
list<string> mynames<-["a","b"];
reflex update_charts
{
myvalues<- [(ant collect each.val1),(ant collect each.val2)];
}
output {
display ChartHistoList {
chart "DataListBar" type:histogram style:"3d"
{
datalist legend:["val1","val2"] categoriesnames:mynames value:myvalues style:stack;
}
}
}
}
(the result image is the same)
3) If you really want to use loop and data statement, you have to wait for me to correct the bug :)
Philippe