Il modo migliore per tracciare il grafico di GraphBuilder con più variabili Y utilizzando JSLTutto,
Vorrei chiedere un input sul modo migliore per scrivere un grafico GB con più parametri.
Diciamo che ho una tabella come questa:
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] )
)
)E voglio scrivere una trama come questa:

dove lo script generato automaticamente ha questo aspetto:
;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" ) ) )
)
con la cattura che c'è un numero arbitrario di colonne Y e anche i nomi sono arbitrari.
Per grafici come il grafico della variabilità vorrei qualcosa del genere:
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 )
)
);dove ricevo i nomi delle colonne come un elenco e quindi costruisco un'espressione Y e poi la inserisco nello script per il grafico. Mi darebbe un elenco di grafici di variabilità, ma per me va bene.
Se voglio seguire lo stesso percorso nel caso del GB, sembra che dovrò costruire due espressioni:
Y( :Value1 ), Y( :Value2, Position( 1 ) )
E
Elements( Bar( X, Y( 1 ), Y( 2 ), Legend( 4 ), Summary Statistic( "Range" ) ) )
Che è essenzialmente l'intera sceneggiatura.
La mia domanda: c'è un modo migliore piuttosto che fare un mucchio di sostituzioni con espressioni per assemblare queste due righe?
Grazie!
Consumatori e ricerche di mercatoRi: Il modo migliore per tracciare il grafico di GraphBuilder con più variabili Y utilizzando JSLCarino!Grazie per aver aggiunto quel tocco.Vorrei averlo provato io stesso!
Ri: Il modo migliore per tracciare il grafico di GraphBuilder con più variabili Y utilizzando JSL@pmroz ecco lo stesso codice senza Eval(Parse()).Sono d'accordo che questo è molto più pulito!
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 ) ) )
);
Ri: Il modo migliore per tracciare il grafico di GraphBuilder con più variabili Y utilizzando JSLNon dimenticare il PILA comando.Richiede eval(parse()) ma è abbastanza pulito altrimenti.Ecco un esempio con tre colonne da tracciare.
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 ) ) )
);

Ri: Il modo migliore per tracciare il grafico di GraphBuilder con più variabili Y utilizzando JSLQuesto usa ancora i cicli per costruire quelle espressioni, ma concatena elenchi di argomenti invece di sostituirli:
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 ) ) )
)
) );Ri: Il modo migliore per tracciare il grafico di GraphBuilder con più variabili Y utilizzando JSLDi solito ho usato metodi simili a te per creare tali costruttori di grafici, questa potrebbe essere una buona lettura Re: Puoi costruirlo senza scrivere espressione una stringa?
Ri: Il modo migliore per tracciare il grafico di GraphBuilder con più variabili Y utilizzando JSLOk, è così che l'ho risolto, ma c'è un modo più semplice? Non riesco a credere che per scrivere una cosa così semplice debba entrare in quel tipo di complessità...:
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 )
)
);