建立隨時間變化類別的時間軸水平長條圖大家好,
我有一個資料表,其中包含一堆在不同時間段屬於不同類別的單位。此資料集在資料表中定義如下:有四列資料 - (i) 單位識別碼(離散數字)、(ii) 開始日期、(iii) 結束日期和 (iv) 類別。類別列列出了單位在開始時間和結束時間之間所屬的類別。給定單元可以具有對應於不同時期的多行資料。數據表如附件。
我正在嘗試創建一個圖表 - 以 X 軸為時間,Y 軸為單位,對於每個單位,我需要一個水平條形圖,透過顏色顯示給定時間段的類別。我附上圖表草圖以顯示圖表的外觀。草圖是為了驅動我對圖表的想法。
我盡了最大努力,但無法得到我想要的東西。感謝您對此的幫助。透過圖形產生器或 JSL 腳本都可以。我使用的是 JMP 16 pro。
數據探索和視覺化回覆:建立隨時間變化類別的時間軸水平長條圖這是您應該能夠擴展的腳本的開頭。我運行了甘特圖附加元件,它不允許每行有多個範圍,並向腳本中添加了一些項目來執行您想要的操作。

Names Default To Here( 1 );
dt = Current Data Table();
gb = Graph Builder(
Size( 1121, 626 ),
Show Control Panel( 0 ),
Variables(
X( :Start Date ),
X( :End Date, Position( 1 ) ),
Y( :Unit/*, Order By( :Start Date, Descending, Order Statistic( "Mean" ) )*/ )
),
Elements( Bar( X( 1 ), X( 2 ), Y, Legend( 32 ), Bar Style( "Range" ) ) ),
SendToReport(
Dispatch(
{},
"Start Date",
ScaleBox,
{Min( 3790824458.85 ), Max( 3734876513.055 ), Interval( "Week" ), Inc( 1 ), Minor Ticks( 0 ),
Label Row( Label Orientation( "Angled" ) )}
),
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
32,
Level Name( 0, "Span of Task", Item ID( "Mean(Start Date)..Mean(End Date)", 1 ) ),
Properties( 0, {Fill Color( 2 )}, Item ID( "Mean(Start Date)..Mean(End Date)", 1 ) )
)}
),
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Gantt Chart" )} ),
Dispatch( {}, "X title", TextEditBox, {Set Text( "Date" )} ),
Dispatch( {}, "Y title", TextEditBox, {Set Text( "Tasks" )} )
)
);
// set axis values
offset = (Col Max( :end date ) - Col Min( :end date )) / 20;
gbr = gb << report;
gbr["Graph Builder", AxisBox( 1 )] << Min( Col Min( :start date ) - offset );
gbr["Graph Builder", AxisBox( 1 )] << Max( Col Max( :end date ) + offset );
// Add the display
gbr["Graph Builder", FrameBox( 1 )] << Add Graphics Script(
// Get Category values
Summarize( dt, catGroups = by( :Category ) );
For Each Row(
Fill Color( Contains( catGroups, :category ) + 2 );
Rect( :Start Date, Num( :unit ) - .9, :End Date, Num( :unit ) - 1.1, fill = 1 );
);
)
;
回覆:建立隨時間變化類別的時間軸水平長條圖太感謝了!您的解決方案幾乎完全符合我的要求。我無法完全理解您如何操縱數據以獲得每個時間段的不同色條。以下是您的腳本中的兩個問題:
1. 如何顯示每個類別的圖例?在右上角? - 就像表格中的數值 A、B、C、D、E 等?是否也可以將它們顯示在每個單元的每個色條上方或內部?
2. 我看到紅色條後面有白色矩形空間。它們是什麼?我可以不在圖表中顯示它們嗎?
感謝您幫助進一步完善這一點。多謝!
回覆:建立隨時間變化類別的時間軸水平長條圖JMP 沒有內建圖表來產生您想要的內容。但是,它確實能夠修改預設圖表以獲得您想要的內容。因此,我之前提供的 JSL 添加了更多註釋,下面列出了使用圖形生成器平台來創建所需圖形的通用形式,然後腳本向其中添加圖形,從而提供所需的結果,並且刪除原始結果。在我的第一個腳本清單中,我只是更改了原始 GB 產生的條形,以使用白色顯示。但是,我已將其更改為僅刪除原始欄。原始條形是您在圖表背景中看到的內容。
關於傳奇,它需要被創造。你需要接受這個挑戰。首先,你需要研究當前的腳本。雷阿
Names Default To Here( 1 );
dt = Current Data Table();
// The Graph Builder Platform currently does not have the capability to create the
// needed Gantt like chart. The main issue is that it does not apppear that Graph
// Builder can display more than one Range Bar on a given line. If more than one
// range is input, then Graph Builder averages the start values and then averages
// the end values, and creates a range bar with the averaged values.
// However, Graph Builder does create a display window with the correct Axes etc.
// So the JSL below runs the Graph Builder Platform, and then adds the Gantt like
// bars, and then finally, deletes the original bars that Graph Builder created.
gb = Graph Builder(
Size( 1121, 626 ),
Show Control Panel( 0 ),
Variables(
X( :Start Date ),
X( :End Date, Position( 1 ) ),
Y( :Unit )
),
Elements( Bar( X( 1 ), X( 2 ), Y, Legend( 32 ), Bar Style( "Range" ) ) ),
SendToReport(
Dispatch(
{},
"Start Date",
ScaleBox,
{Min( 3790824458.85 ), Max( 3734876513.055 ), Interval( "Week" ), Inc( 1 ), Minor Ticks( 0 ),
Label Row( Label Orientation( "Angled" ) )}
),
Dispatch(
{},
"400",
ScaleBox,
{Legend Model(
32,
Level Name( 0, "Span of Task", Item ID( "Mean(Start Date)..Mean(End Date)", 1 ) )
)}
),
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Gantt Chart" )} ),
Dispatch( {}, "X title", TextEditBox, {Set Text( "Date" )} ),
Dispatch( {}, "Y title", TextEditBox, {Set Text( "Tasks" )} )
)
);
// set axis values of the graph to make sure the complete date range is displayed
// Set the min date displayed to the earliest date - 5% of the overall range
// Set the max date displayed to the latest date + 5% of the overall range
offset = (Col Max( :end date ) - Col Min( :end date )) / 20;
gbr = gb << report;
gbr["Graph Builder", AxisBox( 1 )] << Min( Col Min( :start date ) - offset );
gbr["Graph Builder", AxisBox( 1 )] << Max( Col Max( :end date ) + offset );
// Add the color bars to the display
gbr["Graph Builder", FrameBox( 1 )] << Add Graphics Script(
// Get Category values
Summarize( dt, catGroups = by( :Category ) );
// Loop through each row in the data table and draw a filled rectangle on the
// display
For Each Row(
Fill Color( Contains( catGroups, :category ) + 2 );
Rect( :Start Date, Num( :unit ) - .9, :End Date, Num( :unit ) - 1.1, fill = 1 );
);
);
// Delete the bars created by Graph Builder
theBarSeg = gbr["Graph Builder", FrameBox( 1 )] << find seg( bar seg);
theBarSeg << delete;
d 腳本指南,並熟悉腳本索引。然後你就可以開始建造傳奇了。