- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
How do I make start/stop bar charts?
Suppose I have this data:
Step | Start | Stop |
mixer | 0 | 2 |
heater1 | 1 | 12.3 |
injector1 | 4 | 4.5 |
mixer | 6 | 8 |
heater2 | 10.3 | 13 |
injector1 | 12 | 12.5 |
heater1 | 16 | 25.4 |
mixer | 18 | 20 |
heater2 | 23.4 | 30 |
mixer | 24 | 26 |
fan | 24 | 45 |
mixer | 30 | 40 |
... and I want to make this plot (just the bars):
Is that possible with GraphBuilder? (note this image is a mockup with PowerPoint)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
Hi @BHarris,
I'm not able to reproduce directly what you present in powerpoint, but I may have something similar enough to what you intend to have :
Unlike your image, the different ranges are not completely aligned, as I need to have a unique identifier for each values range.
I think the bars could be enlarged for better readability.
You can have a look at the script in the attached datatable.
EDIT: Using a ID column with less levels, the bar graph looks better :
Both graph scritps are saved in the attached datatable.
"It is not unusual for a well-designed experiment to analyze itself" (Box, Hunter and Hunter)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
Nice approach : )
As an alternative to Overlay, one could also use the ID nested on the Y axis:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
Both of these options create a lot of whitespace because each on/off gets its own horizontal row, and there can be a lot of on/offs in my use-case. The bar-plots have a red-triangle "overlap" setting that seems like it should work, but even at "Full" it doesn't seem to do anything, so I was hoping there might be a hidden option or a JSL approach that would keep the bars aligned vertically.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
There are many JSL options for something like this. Set Marker Expr would most likely be the best if you can figure how that is used (it doesn't really have documentation). Here is my quick take using Set Marker Draw Expr, this can be made simpler using just one marker but having two lets user "select" the row from both ends
Names Default To Here(1);
dt = New Table("Untitled 2",
Add Rows(12),
Compress File When Saved(1),
New Column("Step",
Character,
"Nominal",
Set Property("Value Colors", {"fan" = -15113984, "heater1" = -5682409, "heater2" = -40563, "injector1" = -29362, "mixer" = -13983232}),
Set Values({"mixer", "heater1", "injector1", "mixer", "heater2", "injector1", "heater1", "mixer", "heater2", "mixer", "fan", "mixer"})
),
New Column("Start",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([0, 1, 4, 6, 10.300000000000001, 12, 16, 18, 23.399999999999999, 24, 24, 30])
),
New Column("Stop",
Numeric,
"Continuous",
Format("Best", 12),
Set Values([2, 12.300000000000001, 4.5, 8, 13, 12.5, 25.399999999999999, 20, 30, 26, 45, 40])
)
);
dt << Color or Mark by Column(:Step, Color(1), Marker(0));
gb = dt << Graph Builder(Variables(X(:Start), X(:Stop, Position(1)), Y(:Step), Color(:Step)),
Elements(Points(X(1), X(2), Y, Legend(7))),
SendToReport(
Dispatch({}, "400", ScaleBox,
{Legend Model(
7,
Properties(0, {Marker("FilledSquare")}, Item ID("fan", 1)),
Properties(1, {Marker("FilledSquare")}, Item ID("heater1", 1)),
Properties(2, {Marker("FilledSquare")}, Item ID("heater2", 1)),
Properties(3, {Marker("FilledSquare")}, Item ID("injector1", 1)),
Properties(4, {Marker("FilledSquare")}, Item ID("mixer", 1))
)}
),
Dispatch({}, "400", LegendBox,
{Legend Position({7, [0, 1, 2, 3, 4, -1, -1]})}
)
)
);
frame = Report(gb)[FrameBox(1)];
seg = (frame << FindSeg(Marker Seg(1)));
seg << Set Marker Draw Expr(
Function({this seg, this row, x, y, size, row state},
Fill Color(Color Of(Row State(this row)));
Rect(x, y + 0.3, x + (:Stop[this row] - x) / 2 + 0.1, y - 0.3, 1)
)
);
seg = (frame << FindSeg(Marker Seg(2)));
seg << Set Marker Draw Expr(
Function({this seg, this row, x, y, size, row state},
Fill Color(Color Of(Row State(this row)));
Rect(x - (x - :Start[this row]) / 2 - 0.1, y + 0.3, x, y - 0.3, 1)
)
);
There are also most likely options where you heavily modify your data to fit just graphing needs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
wow, this is amazing!
Maybe remove the "/2" and draw 2 overlapping rectangles. Then the bars stays stable even if start or stop is close to the edge or even outside of the graph.
- Chapters
- descriptions off, selected
- captions settings, opens captions settings dialog
- captions off, selected
- en (Main), selected
This is a modal window.
Beginning of dialog window. Escape will cancel and close the window.
End of dialog window.
This is a modal window. This modal can be closed by pressing the Escape key or activating the close button.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
There are basically infinite amount of ways of doing this. Pick which best suits for needs (or create your own). Rect from start to end while utilizing average point allows easily using start/stop markers for example while adding extra "marker" to center for user to click.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
Instead of
Color Of(Row State(this row))
can Set Marker Draw Expr() also use the the color theme defined via the Color dropzone?
Is there a built-in function which does something like
w= current window() << get namespace;
// get the script - and from there the first color
gbscript = gb << get script;
vars = Extract Expr( gbscript, Variables( Wild List() ) );
w:colorCol = Try(
Arg( Extract Expr( vars, Color( Wild() ) ), 1 ),
Caption( "no color" );
stop;
);
// use the legend server to gt the gradient settings
legend = gb << get legend server;
items = {};
For Each( {list}, legend << get legend items, Insert Into( items, list ) );
gradient = Filter Each( {item}, items, item << get Type == "Gradient" );
If( Not( N Items( gradient ) ),
Caption( "no gradient" );
Stop();
);
gradient = gradient[1];
// parse the gradient settings to create my own color interpolation function
settings = gradient << Get Gradient Settings;
colorTheme = settings["Color Theme"];
colors = If( Is List( colorTheme ),
colorTheme[3],
Get Color Theme Detail( colorTheme )[3]
);
colors = Matrix( Remove( colors, N Items( colors ) ) );
xs = ((1 :: N Items( colors[0, 1] )) - 1) / (N Items( colors[0, 1] ) - 1);
scale = settings["Scale Values"];
reverse = settings["Reverse Gradient"];
min = scale[If( reverse, 2, 1 )];
max = scale[If( reverse, 1, 2 )];
Eval(
Eval Expr(
w:col = Function( {x},
x2 = (x - Expr( min )) / (Expr( max - min ));
Eval List(
{Interpolate( x2, xs, Expr( colors[0, 1] ) ), Interpolate( x2, xs, Expr( colors[0, 2] ) ),
Interpolate( x2, xs, Expr( colors[0, 3] ) )}
);
)
)
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How do I make start/stop bar charts?
Here is my approach to creating the graph
Names Default To Here( 1 );
dt = Current Data Table();
gb = Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Variables( X( :Start ), X( :Stop, Position( 1 ) ), Y( :Step ), Color( :Step ) ),
Elements( Points( X( 1 ), X( 2 ), Y, Legend( 12 ) ) ),
SendToReport(
Dispatch( {}, "400", ScaleBox,
{Legend Model(
12,
Properties( 5, {Marker( "FilledCircle" )}, Item ID( "Start", 1 ) ),
Properties( 6, {Marker( "FilledCircle" )}, Item ID( "Stop", 1 ) )
)}
),
Dispatch( {}, "graph title", TextEditBox, {Set Text( "Start - Stop Chart" )} )
)
);
// Remove Start and Stop from legend
lgnd = gb << Get Legend Display;
items = lgnd << Get Items;
For Each( {item}, items,
If( item << Get Label == "Start" | item << Get Label == "Stop",
item << Set Visible( 0 )
)
);
// Set default Value Colors if not set
if( isEmpty(dt:step << get property( "value colors" )),
dt:step << set property( "value colors", "" );
);
// Get the colors to use
colors = dt:step << get property( "value colors" );
// Find the labels for the Y Axis
Summarize( dt, levels = by( :step ) );
// Add a Graphics Script to create the bars on the graph
fb = Report( gb )[framebox( 1 )];
fb << add graphics script(
// Get the colors to use
colors = dt:step << get property( "value colors" );
For Each Row(
cpoint = Contains( levels, :step ) - 1;
Fill Color( Num( Word( 3, Char( colors[cpoint + 1] ), " " ) ) );
Rect( :start, cPoint + .4, :stop, cPoint - .4, 1 );
);
);