根据给定的 RGB 值设置行颜色嗨,我正在尝试通过列中给定的 RGB 值设置行颜色(而不是单元格颜色)。但是,我无法获得正确的循环来分配我想要的自定义颜色。有人能帮忙吗?
附上代码和数据表。谢谢!
// Get the current data table
dt = Current Data Table();
// Initialize the color lists
RedList = Column(dt, "Red") << Get Values;
GreenList = Column(dt, "Green") << Get Values;
BlueList = Column(dt, "Blue") << Get Values;
// Ensure we do not exceed the number of rows or the number of items in any color list
minLength = Min( N Rows(dt), N Items(RedList), N Items(GreenList), N Items(BlueList) );
// Loop to set the row colors
For( i = 1, i <= minLength, i++,
// Clear any previous selections
dt << Clear Select;
// Select the current row
dt << Select Where( Row() == i );
// Set the row color
dt << Set Row Colors( RedList[i], GreenList[i], BlueList[i] );
);
自动化和脚本回复:通过给定的 RGB 值设置行颜色由于所有选择都在进行,因此这会有点慢
Names Default To Here(1);
dt = Current Data Table();
dt << show window(0);
For Each Row(dt,
dt << Clear Select;
dt << Select Rows(Row());
dt << Colors(RGB Color(Eval List({:Red, :Green, :Blue}) / 255));
);
dt << show window(1);
如果需要更快的速度,可以通过选择多行(同时具有特定颜色的所有行)或设置行状态来加快速度。
Names Default To Here(1);
dt = Current Data Table();
Summarize(dt, uniq = By(:Color), r = Min(:Red), g = Min(:Green), b = Min(:Blue));
For Each({cur_color, idx}, uniq,
dt << Select Where(:Color == cur_color);
dt << Colors(RGB Color(Eval List({r[idx], g[idx], b[idx]}) / 255));
dt << Clear Select;
);

漂亮的图片!
编辑:
我突然想到你也可以使用汇总表来设置颜色
Names Default To Here(1);
dt = Current Data Table();
dt_summary = dt << Summary(
Group(:Color),
Mean(:Red),
Mean(:Green),
Mean(:Blue),
Freq("None"),
Weight("None"),
statistics column name format("column")
);
For Each Row(dt_summary,
dt_summary << Select Rows(Row());
dt_summary << Colors(RGB Color(Eval List({:Red, :Green, :Blue}) / 255));
dt_summary << Clear Select;
);
Close(dt_summary, no save);
编辑2:还有一个选项循环遍历整个表格,但没有选择
Names Default To Here(1);
dt = Current Data Table();
For Each Row(dt,
Row State(Row()) = Color State(Eval List({:Red, :Green, :Blue} / 255));
);
我不知道如何将颜色状态(例如颜色状态(-15527920))转换为数字(应该是 512.925536155701),所以我可以构建行状态矩阵并使用<<设置行状态。
回复:通过给定的 RGB 值设置行颜色谢谢!这些解决方案确实有效且高效!
回复:通过给定的 RGB 值设置行颜色2 件事
- 设置行状态颜色的语法不正确。
- 使用 Select Where() 使得循环非常慢。
这是我的修改
// Get the current data table
dt = Current Data Table();
// Initialize the color lists
RedList = Column(dt, "Red") << Get Values;
GreenList = Column(dt, "Green") << Get Values;
BlueList = Column(dt, "Blue") << Get Values;
// Ensure we do not exceed the number of rows or the number of items in any color list
minLength = Min( N Rows(dt), N Items(RedList), N Items(GreenList), N Items(BlueList) );
// Loop to set the row colors
For( i = 1, i <= minLength, i++,
// Clear any previous selections
dt << Clear Select;
// Select the current row
dt << Select rows( i );
// Set the row color
dt << Colors( rgb color(redlist[i],greenlist[i],bluelist[i]) );
);回复:根据给定的 RGB 值设置行颜色抱歉翻出这么老的帖子,但我刚才费了一番功夫才弄明白。我之前也尝试过把颜色状态转换成数字,但没成功。后来我找到了一种更快的方法,因为它避免了循环。虽然感觉有点作弊,但创建一个公式列,然后让 JMP 使用内置函数复制这些行状态,速度比@jthi之前用 Edit2 实现的快得多。
(dt << new column ("Color", formula (color state (RGB color (:R, :G, :B))))) << copy to row states;