你好。 我在圖形生成器中編寫條形圖腳本,因為使用標準圖表並不能像圖形生成器那樣消除空條。 我允許使用連續建模類型作為 X 因素。 讓我解釋一下我是如何處理這個問題的。
使用者選擇一些列來繪製長條圖。 我使用圖形產生器建立圖表並選擇第一列。 然後,如果選擇了多個列,我會進入並<<將變數新增至圖形產生器。 這與我想要的完全一樣,除非選定的列之一是連續的。 然後,圖形生成器將整個 X 替換為連續變量,並表示那裡還有更多變量,但它只是相對於一個進行繪圖。 當我透過將連續變數更改為序數來手動建立圖表時,它會按照我想要的方式工作。 因此,我將每個連續列更改為原始列,但圖形仍然沒有添加變數而是替換了它。
有誰知道如何讓這份工作以我想要的方式進行? 這是我的腳本的簡化版本:
myWin = Column Dialog( FactorCol = Col List( "Multivariate Factor(s)" ) );
myFactor = myWin["FactorCol"];
myPlot = Graph Builder(
Show Control Panel( 0 ),
Show Legend( 0 ),
Variables( X( Eval( myFactor[1] ) ), Y( yCol ), Color( Eval( myColor ) ) ),
Elements( Bar( X, Y, Summary Statistic( "Std Dev" ), Label( "Label by Value" ) ) ),
SendToReport(
Dispatch(
{},
ScaleBox,
{Label Row( 1, {Automatic Tick Marks( 0 ), Show Major Ticks( 1 ), Lower Frame( 1 ), Tick Mark Style( "Long Divider" )} )}
)
)
);
//If there is more than one factor then need to add variables to the graph
If( N Items( myFactor ) > 1,
myRep = Report( myPlot )[Graph Builder Box( 1 )];
For( j = 2, j <= N Items( myFactor ), j++,
xcol = Column( dtmm, myFactor[j] );
If( xcol << Get Modeling Type == "Continuous",
//set a column property so I can change it back later
xcol << Set Property( "change", 1 );
xcol << Modeling Type( "Ordinal" );
);
myRep << Add Variable( {xcol, Role( "X" ), Position( 1 )} );
);
//now I have to adjust all the x-axis for the way I want it
For( j = 1, j <= N Items( myFactor ), j++,
Report( myPlot )[Axisbox( 1 )] << {Label Row(
j,
{Automatic Tick Marks( 0 ), Show Major Ticks( 1 ), Lower Frame( 1 ), Tick Mark Style( "Long Divider" )}
)}
);
);
實際上,我透過逐步檢查圖形產生器框的變數找出如何做到這一點。 如果列是連續的,我將其變更為序數,並且在新增變數時,必須新增內部位置項目。 這是相關的腳本位。
//graph builder can not add factors unless they are ordinal or nominal
//so if it is continuous, change to ordinal, and set a column property to change back later
If( xcol << Get Modeling Type == "Continuous",
xcol << Set Property( "change", {1} );
xcol << Modeling Type( "Ordinal" );
myRep << Add Variable( {xcol, Role( "X" ), Position( 1 ), Inner Position[i]} ),
,
myRep << Add Variable( {xcol, Role( "X" ), Position( 1 )} )
);這正是我想要它所做的。
H
謝謝。 是的,我知道創建字串腳本是一種選擇,但我總是不願意這樣做。 但在這種情況下可能是必要的。我對事實如此感到失望。
最好的
H