使用 JSL 绘制具有多个 Y 变量的 GraphBuilder 图的最佳方法全部,
我想询问编写具有多个参数的 GB 图脚本的最佳方法。
假设我有一个这样的表:
New Table( "Untitled 140",
Add Rows( 12 ),
New Column( "Category",
Character,
"Nominal",
Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} )
),
New Column( "Value1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] )
),
New Column( "Value2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] )
)
)我想编写这样的情节:

自动生成的脚本如下所示:
;Graph Builder(
Size( 522, 450 ),
Show Control Panel( 0 ),
Variables( X( :Category ), Y( :Value1 ), Y( :Value2, Position( 1 ) ) ),
Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 4 ), Summary Statistic( "Range" ) ) )
)
问题是 Y 列的数量是任意的,并且名称也是任意的。
对于像变异图这样的图,我会这样:
parameters = {:"Value1"n, :"Value2"n};
yExpr = Expr( Y() );
For Each( {value, index}, parameters, Insert Into( yExpr, Name Expr( value ), 1 ) );
Eval(
Substitute(
Expr(
Variability Chart( placeholder, X( :Category ), Std Dev Chart( 0 ) )
),
Expr( placeholder ), Name Expr( yExpr )
)
);我在其中接收列名称作为列表,然后构造一个 Y 表达式,然后将其放入图表的脚本中。 它会给我一个变异图列表,但这对我来说没问题。
如果我想在 GB 的情况下采取相同的路线,看起来我将不得不构造两个表达式:
Y( :Value1 ), Y( :Value2, Position( 1 ) )
和
Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 4 ), Summary Statistic( "Range" ) ) )
这基本上就是整个脚本。
我的问题:有没有更好的方法而不是用表达式进行一堆替换来组装这两行?
谢谢!
消费者和市场研究回复:使用 JSL 绘制具有多个 Y 变量的 GraphBuilder 图的最佳方法好的!感谢您添加这种感觉。希望我自己也尝试过!
回复:使用 JSL 绘制具有多个 Y 变量的 GraphBuilder 图的最佳方法@pmroz这是没有 Eval(Parse()) 的相同代码。我同意这更干净!
Names default to here(1);
dt = New Table( "Test",
Add Rows( 12 ),
New Column( "Category", Character, "Nominal",
Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} ) ),
New Column( "Value1", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] ) ),
New Column( "Value2", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] ) ),
New Column( "Value3", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [1, 4, 3, 6, 5, 7, 3, 4, 2, 8, 6, 1] ) )
);
dt_cols = dt << get column references();
remove from(dt_cols, 1); // Remove Category
dts = dt << Stack(invisible,
columns( dt_cols ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" )
);
dts << Graph Builder(
Size( 518, 448 ),
Show Control Panel( 0 ),
Variables( X( :Category ), Y( :Data ), Overlay( :Label ) ),
Elements( Bar( X, Y, Legend( 7 ) ) )
);
回复:使用 JSL 绘制具有多个 Y 变量的 GraphBuilder 图的最佳方法不要忘记堆命令。需要 eval(parse()) 但它在其他方面非常干净。这是一个要绘制三列的示例。
dt = New Table( "Test",
Add Rows( 12 ),
New Column( "Category",
Character,
"Nominal",
Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} )
),
New Column( "Value1",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] )
),
New Column( "Value2",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] )
),
New Column( "Value3",
Numeric,
"Continuous",
Format( "Best", 12 ),
Set Values( [1, 4, 3, 6, 5, 7, 3, 4, 2, 8, 6, 1] )
)
);
dt_cols = dt << get column names(string);
removefrom(dt_cols, 1); // Remove Category
// Create the list of columns, like this: ":Value1, :Value2, :Value3"
col_list = ":" || concat items(dt_cols, ", :");
stack_str = evalinsert(
"\[dts = dt << Stack(invisible,
columns( ^col_list^ ),
Source Label Column( "Label" ),
Stacked Data Column( "Data" ))]\");
eval(parse(stack_str));
dts << Graph Builder(
Size( 518, 448 ),
Show Control Panel( 0 ),
Variables( X( :Category ), Y( :Data ), Overlay( :Label ) ),
Elements( Bar( X, Y, Legend( 7 ) ) )
);

回复:使用 JSL 绘制具有多个 Y 变量的 GraphBuilder 图的最佳方法这仍然使用循环来构建这些表达式,但它连接参数列表而不是替换它们:
Names default to here(1);
//call another function (f) with the arguments provided in a list (l)
do.call = function({l,f},
Substitute(
Name Expr(l),
Expr({}),
Name Expr(f)
);
);
dt = New Table( "Data",
Add Rows( 12 ),
New Column( "Category", Character, "Nominal",
Set Values( {"A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"} )
),
New Column( "Value1", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [1, 4, 2, 3, 6, 2, 3, 5, 4, 1, 3, 6] )
),
New Column( "Value2", Numeric, "Continuous", Format( "Best", 12 ),
Set Values( [6, 3, 5, 2, 8, 6, 5, 2, 6, 3, 5, 4] )
)
);
vars = {:Value1, :Value2};
VarExpr = do.call(
{ X( :Category ) } || transform each({v}, vars, eval expr( Y( Expr( Name Expr( v ) ), Position( 1 ) ) ) ),
expr(Variables())
);
BarExpr = do.call(
{ X } || transform each({v, i}, vars, eval expr( Y( Expr( i ) ) ) ) || { Legend( 4 ), Summary Statistic( "Range" ) },
expr(Bar())
);
Eval( Eval Expr(
dt << Graph Builder(
Size( 522, 450 ),
Show Control Panel( 0 ),
Expr( Name Expr( VarExpr ) ),
Elements( Expr( Name Expr( BarExpr ) ) )
)
) );回复:使用 JSL 绘制具有多个 Y 变量的 GraphBuilder 图的最佳方法我通常使用与您类似的方法来构建此类图形生成器,这可能是一本很好的读物回复:您可以在不将表达式写入字符串的情况下构造这个吗?
回复:使用 JSL 绘制具有多个 Y 变量的 GraphBuilder 图的最佳方法好吧,我就是这样解决的,但是有没有更简单的方法呢? 不敢相信要编写如此简单的脚本,我需要考虑这种复杂性......:
parameters = {:"Value1"n, :"Value2"n};
yExpr = Expr( Y() );
yExprPos = Expr( Y( Position( 1 ) ) );
barExpr = Expr(
Bar( X, Summary Statistic( "Range" ) )
);
yNExpr = Expr( Y() );
variablesExpr = Expr(
Variables( X( :Category ) )
);
For Each( {value, index}, parameters,
Insert Into( yExpr, Name Expr( value ), 1 );
yExprPos = Expr( Y( Position( 1 ) ) );
Insert Into( yExprPos, Name Expr( value ), 1 );
Insert Into( variablesExpr, Name Expr( yExprPos ) );
//This is for Y(1) etc. in Bar()
yNExpr = Expr( Y() );
Insert Into( yNExpr, Name Expr( index ) );
Insert Into( barExpr, Name Expr( yNExpr ), 2 );
);
//Name Expr( yExpr );
Show(Name Expr( variablesExpr ));
Show(Name Expr( barExpr ));
gbExpr = Expr(
Graph Builder( Size( 522, 450 ), Show Control Panel( 0 ), placeholder1, Elements( placeholder2 ) )
);
Eval(
Substitute(
Substitute(
Name Expr(gbExpr),
Expr( placeholder1 ),
Name Expr( variablesExpr )
),
Expr( placeholder2 ),
Name Expr( barExpr )
)
);