你好,
我有时间序列数据,其中的时间块被分解为不同的“周期”,我正在尝试找到一种方法来创建标记每个周期开始的参考线。我希望当我在试验中更改本地数据过滤器时这些参考线会更新(因为不同试验的周期开始时间不同)。
起初,我使用本地数据过滤器,使用Make Row State Handler 检测本地数据过滤器中的变化。但是,我无法弄清楚如何从本地数据过滤器中获取必要的信息(即正在过滤的试验 - 尽管我可能已经使用本地数据过滤器上的Get Where Clause接近了),因此无法知道正在过滤的试验,并让它决定使用哪些周期时间来创建参考线。(但是,如果您认为这是一种更好的方法,请告诉我)。
因此,我决定不再让用户与本地数据过滤器交互并尝试读取过滤器来过滤试验,而是向用户提供试验列表,然后根据用户选择的试验添加过滤器,同时使用选择来指示使用哪些周期时间来创建参考线。
但是,我无法添加当用户选择不同的试用号码时会发生变化的参考线。
请在下面找到我的代码。
//Reference Lines that Update With Change in Local Data Filter
// Example Data
dt = New Table( "Example",
Add Rows( 3 ),
New Column( "Trial",
character,
"Ordinal",
Set Values( {"A","A","A","A","A","A","A","A","A","A","A","A","A","A","B","B","B","B","B","B","B","B","B","B","B","B","B","B"} )
),
New Column( "Cycle",
Character,
"Ordinal",
Set Values( {"Rinse","Rinse","Rinse","Wash","Wash","Wash","Wash","FinalRinse","FinalRinse","FinalRinse","FinalRinse","Dry","Dry","Dry","Rinse","Rinse","Rinse","Wash","Wash","Wash","Wash","FinalRinse","FinalRinse","FinalRinse","FinalRinse","Dry","Dry","Dry
"} )
),
New Column( "%Clean",
Numeric,
"Continuous",
Set Values( {10,20,25,50,60,70,80,85,90,95,99,99,99,99,10,25,30,60,75,85,90,95,99,99.9,99.99,99.99,99.99,99.99} )
),
New Column( "Time",
Numeric,
"Continuous",
Set Values( {1,2,3,4,5,6,7,8,9,10,11,12,13,14,2,4,6,8,10,12,14,16,18,20,22,24,26,28} )
),
);
dt = current data table();
//Function to pull cycle start times (where reference lines will be drawn)
genRefLineValue = function({trialNum = "A", cycleNum = "Rinse"},{myrows,myvalues,min_value},
myrows = dt << get rows where(and(:Trial == trialNum,:Cycle == cycleNum));
myvalues = :Time[myrows];
min_value = min(myvalues);
Return(min_value);
);
//Function to pull unique cycles (I want the start time for EACH of the cycles)
findUniqueCycles = function({trialNum},{myrows,cycles,uniqueCycles},
myrows = dt << get rows where(:Trial == trialNum);
cycles = :Cycle[myrows];
uniqueCycles = associative array(cycles) << get keys;
return(uniqueCycles);
);
//Get unique trials (A, B, etc.)
summarize(unique_values=by(:Trial));
//Create window with radio buttons and graph
New Window( "Example",
HListBox(
PanelBox("Trial", //Adding radio buttons
rb = radio box(
unique_values, <<SET></SET>
At the bottom is where I add the reference lines. If you run the script and select between Trial A and B, you can see that while the filter's working and the data changes accordingly, the reference lines don't change (it might look like they change, but if you observe the actual values, they aren't changing). I've tried using <EM>我的选择</EM> in place of "A" so that the arguments in the loop that is creating the reference lines should update when the user selects Trial B:
<CODE class=" language-jsl">For(i=1,i<= (n items (findUniqueCycles(myChoice))),i++,
cycleName = findUniqueCycles(myChoice)[i];
cycleStart = genRefLineValue(myChoice,findUniqueCycles(myChoice)[i]);
report(biv)[axisbox(2)] << add ref line(cycleStart,"solid",,cycleName ||"(t="||char(cycleStart)||" min)",1.5);
);
But JMP complains by saying:
Name Unresolved: myChoice{3} in access or evaluation of 'myChoice' , myChoice/*###*/How do I make reference lines that update when the user changes their selection among trials?
Thanks in advance!
我想你快到了。
尝试用这个替换你的代码的后面部分
rb << Set Function(
Function( {this},{myChoice},
myChoice = Char( this << get selected );
(this << sib) << Set Text( myChoice );
//print(myChoice);
biv << remove local data filter;
biv << Local Data Filter(invisible, //updating (by removing then re-adding) the local data filter according to user's selection
Add Filter(
columns( :Trial ),
Where( :Trial == myChoice ),
));
if (myChoice == "A",
For(i=1,i<= (n items (findUniqueCycles("B"))),i++,
cycleStart = genRefLineValue("B",findUniqueCycles("B")[i]);
report(biv)[axisbox(2)] << remove ref line(cycleStart);
)
);
if (myChoice == "B",
For(i=1,i<= (n items (findUniqueCycles("A"))),i++,
cycleStart = genRefLineValue("A",findUniqueCycles("A")[i]);
report(biv)[axisbox(2)] << remove ref line(cycleStart);
)
);
For(i=1,i<= (n items (findUniqueCycles(myChoice))),i++,
cycleName = findUniqueCycles(myChoice)[i];
cycleStart = genRefLineValue(myChoice,findUniqueCycles(myChoice)[i]);
report(biv)[axisbox(2)] << add ref line(cycleStart,"solid",,cycleName ||"(t="||char(cycleStart)||" min)",1.5);
);
)
);
report(biv)[framebox(1)] << Frame Size( 1000, 400 );
//you need this to initialize somehow
For(i=1,i<= (n items (findUniqueCycles("A"))),i++,
cycleName = findUniqueCycles("A")[i];
cycleStart = genRefLineValue("A",findUniqueCycles("A")[i]);
report(biv)[axisbox(2)] << add ref line(cycleStart,"solid",,cycleName ||"(t="||char(cycleStart)||" min)",1.5);
);
此外,该错误意味着 myChoice 无法找到或未定义,因为您在它可用的地方之外使用了它,即在回调内部。