Here is very quick version of the script
Names Default To Here(1);
If(Is Empty(Current Report()),
Throw("No open reports found");
);
cur_report = Current Report() << XPath("//OutlineBox[@helpKey='Graph Builder']");
If(N Items(cur_report) < 1,
Throw("No graph builder open");
,
cur_report = cur_report[1] << Get Scriptable Object;
dt = cur_report << Get Data Table;
);
// Find current Color role
find_role_column = Function({gb, role = "Color"}, {Default Local},
vars = gb << Get Variables();
col = "";
role_idx = 0;
For Each({var, idx}, vars,
role = var["Role"];
If(role == "Color",
col = var[1] << get name;
role_idx = idx;
break();
);
);
return(Eval List({col, role_idx}));
);
replace_role_column = function({gb, new_col, role = "Color"}, {Default Local},
{colname, role_idx} = find_role_column(gb);
gb << inval;
If(role_idx > 0,
gb << Remove Variable(role_idx);
);
Eval(EvalExpr(
gb << Add Variable({Expr(NameExpr(AsColumn(new_col))), Role(Expr(role))});
));
wait(0);
gb << update window;
return(1);
);
nw = new window("demo",
clb = Col List Box(Datatable(dt), width(250), maxSelected(1),
<< Set Function(function({this},
replace_role_column(cur_report, this << get selected, "Color");
));
)
);
clb << Set Items(dt << Get Column Names("String"));
Creating better one will take some time and I might have enough time during weekend to create one (it is fairly similar to my Column Quick Swapper - easily change multiple Y and X-axis columns in Graph Builder )
-Jarmo