创建随时间变化类别的时间线水平条形图大家好,
我有一个数据表,其中包含一堆在不同时间段属于不同类别的单位。该数据集在数据表中定义如下:有四列数据 - (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 脚本指南,并熟悉脚本索引。然后你就可以开始建造传奇了。