你好,
我嘗試編寫像這樣的條形圖。
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" )
)
)
)
挑戰是,我在列表中有Y個變量,這些變量會不時變化(例如{A,B,D,Test,Bla})。
我想根據列表“l”自動調整條形圖,例如:
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" )
)
)
)
...
在數據庫查詢後,列表l將被更改,我需要自動更新條形圖。
我已經嘗試將列表轉換為列並循環遍歷列表條目的數量,但它生成多個而不是一個條形圖
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" )
)
)
));
問候,
如果您堆疊所需的列,那麼無論您擁有多少列都無關緊要。 這段代碼應該讓你入門:
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 )} ) )
)