Hallo,
Ich versuche, ein Balkendiagramm wie dieses zu schreiben.
Graph Builder(
Size( 534, 418 ),
Show Control Panel( 0 ),
Variables(
Y( :Name( "A" ) ),
Y( :Name( "B" ), Position( 1 ) ),
Y( :Name( "C" ), Position( 1 ) ),
),
Elements(
Bar(
Y( 1 ),
Y( 2 ),
Y( 3 ),
Legend( 3 ),
Bar Style( "Stacked" )
)
)
)
Die Herausforderung besteht darin, dass ich die Y-Variablen in einer Liste habe, die von Zeit zu Zeit geändert wird (zB {A, B, D, Test, Bla).
Ich möchte, dass das Balkendiagramm abhängig von der Liste "l" automatisch angepasst wird, z. B .:
l = {"A", "B", "D", "Test", "Bla"};
...the script should then be looks like this:
Variables(
Y( :Name( "A" ) ),
Y( :Name( "B" ), Position( 1 ) ),
Y( :Name( "D" ), Position( 1 ) ),
Y( :Name( "Test" ), Position( 1 ) ),
Y( :Name( "Bla" ), Position( 1 ) ),
),
Elements(
Bar(
Y( 1 ),
Y( 2 ),
Y( 3 ),
Y( 4 ),
Y( 5 ),
Legend( 3 ),
Bar Style( "Stacked" )
)
)
)
...
Nach einer Datenbankabfrage wird die Liste l geändert und ich benötige eine automatische Aktualisierung des Balkendiagramms.
Ich habe bereits versucht, die Liste in eine Spalte und eine Schleife über die Anzahl der Listeneinträge umzuwandeln, aber es werden mehrere anstelle eines Balkendiagramms generiert
for (i=1, i <= Nitems(l), i++,
show (l[i]);
dt << Graph Builder(
Size( 534, 418 ),
Show Control Panel( 0 ),
Variables(
Y( Eval (l[i] ))
),
Elements(
Bar(
Y( i ),
Legend( 3 ),
Bar Style( "Stacked" )
)
)
));
Grüße,
Danke, das funktioniert gut!
Wenn Sie die gewünschten Spalten stapeln, ist es egal, wie viele Sie haben. Dieser Code soll Ihnen den Einstieg erleichtern:
dt1 = New Table( "Untitled 27", Add Rows( 3 ),
New Column( "A", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [6, 5, 4] ) ),
New Column( "B", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [7, 8, 9] ) ),
New Column( "C", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3, 2, 1] ) )
);
col_list = dt1 << get column names(string);
dt2 = dt1 << Stack(
columns(col_list),
Source Label Column( "Variable" ),
Stacked Data Column( "Value" )
);
dt2 << Graph Builder(
Size( 526, 415 ),
Show Control Panel( 0 ),
Variables( Y( :Value ), Overlay( :Variable ) ),
Elements( Bar( Y, Legend( 8 ), Bar Style( "Stacked" ) ) ),
SendToReport( Dispatch( {}, "X title", TextEditBox, {Set Wrap( 2 )} ) )
)