你好,
我有時間序列數據,其中時間區塊被分成不同的“週期”,我正在嘗試找到一種方法來創建標記每個週期開始的參考線。我希望當我跨試驗更改本地數據過濾器時更新這些參考線(因為不同試驗的周期在不同時間開始)。
起初,我使用本機資料過濾器,使用Make Row State Handler 偵測本機資料過濾器中的變更。然而,我無法弄清楚如何從本地數據過濾器中獲取必要的資訊(即正在過濾哪些試驗 - 儘管我可能已經在本地數據過濾器上使用GetWhere 子句接近),因此無法知道正在過濾的試驗,並決定使用哪個週期時間來建立參考線。 (但是,如果您認為這是更好的方法,請告訴我)。
因此,我決定向用戶提供一個試驗列表,然後根據試驗的內容添加一個過濾器,而不是讓用戶與本地數據過濾器互動並嘗試讀取過濾器來過濾試驗。哪個循環時間來建立參考線。
但是,我無法新增當使用者選擇不同的試用號時發生變化的參考線。
請在下面找到我的程式碼。
//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 無法找到或未定義,因為您在它可用的地方之外使用了它,即在回調內部。