通过在与图表相同的仪表板上的菜单中进行选择,在图表生成器中动态更新“Color( )”您好 JMP 社区,
我正在使用生成应用程序的 JMP 插件。 此应用程序只有一个模块,并创建一个包含多个图表的仪表板。 它还会创建一个显示框,该显示框嵌入在同一仪表板中,并包含用于生成图形的数据表中的列列表。 当从列表中选择一列时,行状态(具体来说,行颜色)会根据该选择进行更新。 然后,这会反映在根据行状态着色的图表中。 但是,由于图形生成器中的“Color( )”变量仍然为空,因此图形的图例不会根据显示的颜色进行更新。 如果我将带有列列表的显示框显示为模态窗口,我可以根据选择填充“颜色()”字段前生成图表。 不过,这种方法的问题是模态窗口无法嵌入到仪表板中(或者,至少我不知道如何嵌入),而且更重要的是,它不是动态的——您只能进行一次选择在图表生成之前开始,但随后无需再次运行加载项就无法进行其他选择。 我包括了我的代码的摘录。 “win”对象是包含列列表并嵌入在仪表板中的显示框。
JMP App(
Set Name( "Application" ),
Set Description(
"An empty workspace for creating custom applications with one or more windows and scripts"
),
Auto Launch( 1 ),
Snap To Grid( 1 ),
Show Grid( 1 ),
Show Properties( 1 ),
Show Sources( 1 ),
Group By Category( 1 ),
Dashboard Mode( 0 ),
Parameters,
Tables,/*(
DataTable1 = GuiTable(
Set Path(
"/S:/17 - Contacts - Confidential material/Siemens/2018-08 - Bangkok test/05 - Analysis/All component compilation v6 (with Row column).jmp"
),
Set Label( "All component compilation v5" ),
Set Location( "Current Data Table" ),
Set Invisible( 0 )
)
),*/
Script(JSL Quote(// This script is executed when the application is run.
// Named objects have been created for the application modules
// (for example, "Module1") and the pre-defined object
// "thisApplication" refers to the application object itself.
// Variables and functions declared here are scoped to the
// Application namespace.
)),
Allocate(
Module1 = Plan(
PreAllocate,
Script(JSL Quote(// This script is executed when a new module instance is
// created. The pre-defined object "thisModuleInstance" refers
// to the instance object, but other objects such as boxes and
// scripts have not yet been created. Variables declared here are
// scoped to the ModuleInstance namespace.
// This special function will receive parameters passed to CreateInstance()
OnModuleLoad({});
dt = current data table(); //note that dt has to be defined before the thisModuleInstance' object is created. When defined after and the new "Row" column is added, the code does not recognise the new column and so outputs empty plots. This may be due to the namespaces: maybe the dt has to be in the application namespace and the after thisModuleInstance is created, it is in the module namespace.
If( Is Missing (Is Scriptable( Try ( Column( "Row" )))),
dt << New Column( "Row", Numeric, Values( 1 :: N Row() ), Format( "Best", 12 )));
colnames = dt << get column names;
thisModuleInstance << Create Objects;
// After this point your module instance objects have been created
// and can be referred to by name (for example, "Button1").
show(chosen);
)),
Allocate(
Outline1 = Outline Box();
DataFilterContext1 = Data Filter Context Box();
List1 = H List Box();
List2 = V List Box();
DataFilter1 = dt << Data Filter( Local );
win = Platform(
dt,
H List Box(
Panel Box( "Colour by:",
collist = List Box(
colnames,
max selected( 1 ),
chosen = collist << get selected;
col = column(chosen);
dt << Color or Mark by Column( col ),
)
)
)
);
List3 = V List Box();
List4 = H List Box();
Report1 = Platform(
dt,
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window( "Maintain Aspect Ratio" ),
Variables( X( :Row ), Y( :Friction ) ),
Elements(
Points( X, Y, Legend( 9 ) ),
Smoother( X, Y, Legend( 10 ) )
),
)
);
Report2 = Platform(
dt,
Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window( "Maintain Aspect Ratio" ),
Variables( X( :Row ), Y( :Velocity ) ),
Elements(
Points( X, Y, Legend( 6 ) ),
Smoother( X, Y, Legend( 7 ) )
)
)
);
我期待听到您的建议。
谢谢大家!
图形其他脚本回复:通过在与图表相同的仪表板上的菜单中进行选择,在图表生成器中动态更新“Color( )”@gzmorgan0 , 非常感谢及时回复。
您的解决方案有效,所以也感谢您。 我在下面的代码中展示了我如何根据我的需求调整您的解决方案以造福他人。
JMP App(
Set Name( "Application" ),
Set Description(
"An empty workspace for creating custom applications with one or more windows and scripts"
),
Auto Launch( 1 ),
Snap To Grid( 1 ),
Show Grid( 1 ),
Show Properties( 1 ),
Show Sources( 1 ),
Group By Category( 1 ),
Dashboard Mode( 0 ),
Parameters,
Tables,/*(
DataTable1 = GuiTable(
Set Path(
"/S:/17 - Contacts - Confidential material/Siemens/2018-08 - Bangkok test/05 - Analysis/All component compilation v6 (with Row column).jmp"
),
Set Label( "All component compilation v5" ),
Set Location( "Current Data Table" ),
Set Invisible( 0 )
)
),*/
Script(JSL Quote(// This script is executed when the application is run.
// Named objects have been created for the application modules
// (for example, "Module1") and the pre-defined object
// "thisApplication" refers to the application object itself.
// Variables and functions declared here are scoped to the
// Application namespace.
)),
Allocate(
Module1 = Plan(
PreAllocate,
Script(JSL Quote(// This script is executed when a new module instance is
// created. The pre-defined object "thisModuleInstance" refers
// to the instance object, but other objects such as boxes and
// scripts have not yet been created. Variables declared here are
// scoped to the ModuleInstance namespace.
// This special function will receive parameters passed to CreateInstance()
OnModuleLoad({});
dt = current data table(); //note that dt has to be defined before the thisModuleInstance' object is created. When defined after and the new "Row" column is added, the code does not recognise the new column and so outputs empty plots. This may be due to the namespaces: maybe the dt has to be in the application namespace and the after thisModuleInstance is created, it is in the module namespace.
If( Is Missing (Is Scriptable( Try ( Column( "Row" )))),
dt << New Column( "Row", Numeric, Values( 1 :: N Row() ), Format( "Best", 12 )));
colnames = dt << get column names;
thisModuleInstance << Create Objects;
// After this point your module instance objects have been created
// and can be referred to by name (for example, "Button1").
)),
Allocate(
Outline1 = Outline Box();
DataFilterContext1 = Data Filter Context Box();
List1 = H List Box();
List2 = V List Box();
DataFilter1 = dt << Data Filter( Local );
win = Platform(
dt,
H List Box(
Panel Box( "Colour by:",
collist = List Box(
colnames,
max selected( 1 ),
if( chosen != "",
gbb1 << Remove Variable( {col, Role( "Color" )} );
gbb2 << Remove Variable( {col, Role( "Color" )} );
);
chosen = collist << get selected;
col = column(chosen);
dt << Color or Mark by Column( col );
gbb1 = Report( gb1 )[Graph Builder Box( 1 )];
gbb1 << Add Variable( {col, Role( "Color" )} );
gbb2 = Report( gb2 )[Graph Builder Box( 1 )];
gbb2 << Add Variable( {col, Role( "Color" )} );
)
)
)
);
List3 = V List Box();
List4 = H List Box();
Report1 = Platform(
dt,
gb1 = Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window( "Maintain Aspect Ratio" ),
Variables( X( :Row ), Y( :Friction ) ),
Elements(
Points( X, Y, Legend( 9 ) ),
Smoother( X, Y, Legend( 10 ) )
)
)
);
Report2 = Platform(
dt,
gb2 = Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Fit to Window( "Maintain Aspect Ratio" ),
Variables( X( :Row ), Y( :Velocity ) ),
Elements(
Points( X, Y, Legend( 6 ) ),
Smoother( X, Y, Legend( 7 ) )
)
)
);同样,以上只是完整代码的摘录。 正如您在上面看到的,我必须在“win”平台中定义 gbb1 和 gbb2,每次进行新选择时都会运行它。 这在速度方面可能不是最佳的,但如果代码要工作,它似乎是唯一可以定义它们的地方(我不确定为什么)。
再一次谢谢你@gzmorgan0 .
回复:通过在与图表相同的仪表板上的菜单中进行选择,在图表生成器中动态更新“Color( )”@A_Zaid ,
你说
“您只能在生成图形之前在开始时进行一次选择,但之后必须再次运行加载项才能进行另一次选择。 “
实际上那是我们书中的勘误表。 您可以通过向 GraphBuilderBox() 发送消息来添加或删除变量。 请参阅下面的脚本。
您可能必须添加接口才能添加或删除变量。
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Big Class.jmp" );
gb = Graph Builder(
Variables( X( :height ), Y( :weight ) ),
Elements( Points( X, Y ), Smoother( X, Y ) )
);
gbb = Report( gb )[Graph Builder Box( 1 )];
Wait( 0.5 );
gbb << Add Variable( {:sex, Role( "Wrap" )} );
wait( 0.5 );
gbb << Add Variable( {:sex, Role( "Color" )} );
wait( 0.5 );
gbb << Remove Variable( {:sex, Role( "Color" )} );
wait( 0.5 );
gbb << Add Variable( {:age, Role( "Color" )} );