你好。 我在图形生成器中编写条形图脚本,因为使用标准图表并不能像图形生成器那样消除空条。 我允许使用连续建模类型作为 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