Forum Discussion
Stacked Bar chart as a timeline for individual days
- 1 year ago
Alright, I'm pretty new to this and it took me a while to figure out but I've made some progress and would like your opinion to see if I've done this 'correctly' or if it could be more efficient or if you see any flaws. But this is more or less achieving what I've set out to do and could not have done it without your help!
The main change is I created a "ShiftID" to deal with the wrapping for past midnight shifts as sometimes crews can end and start a shift on the same day:
ShiftID =[Team]& "-" &FORMAT ( [Date], "ddmmyyyy" )& "-" &[Machine]This is the updated JSON:
{"data": {"name": "dataset"},"transform": [{"window": [{"op": "min", "field": "StartTime", "as": "ShiftStart"}],"groupby": ["ShiftID"]},{"calculate": "(datetime(datum.StartTime) - datetime(datum.ShiftStart)) / (1000 * 60 * 60)","as": "OffsetStart"},{// Similarly for EndTime"calculate": "(datetime(datum.EndTime) - datetime(datum.ShiftStart)) / (1000 * 60 * 60)","as": "OffsetEnd"}],"mark": "bar","encoding": {"y": {"field": "ShiftID", "type": "nominal"},"x": {"field": "OffsetStart","type": "quantitative","stack": null},"x2": {"field": "OffsetEnd"},"color": {"field": "Description", "type": "nominal"}}}
Apologies for that - here is sample data for 5 days. What I am trying to do is create the 'stacked bar graph timeline' where each day is represented by it's own bar.
I want each day to look like this where the start and end time of an activity is shown by a different colour segment on the bar. Same activity types are shown by the same colour. The length of the bar should always be the same regardless of total minutes worked in a day. Ideally I would want data labels that show the minutes of each segment.
https://docs.google.com/spreadsheets/d/1lRZOKw-j79jNpJo2SwSWH3foJVSH06-x56IitWaqgPE/edit?usp=sharing
Before we get into the finer details of the ask (for example - what should happen when an activity crosses midnight?)
Here is a cheap and cheerful implementation using a Deneb visual. Is that maybe already good enough?
- jaymeyer1 year agoRegular Visitor
Alright, I'm pretty new to this and it took me a while to figure out but I've made some progress and would like your opinion to see if I've done this 'correctly' or if it could be more efficient or if you see any flaws. But this is more or less achieving what I've set out to do and could not have done it without your help!
The main change is I created a "ShiftID" to deal with the wrapping for past midnight shifts as sometimes crews can end and start a shift on the same day:
ShiftID =[Team]& "-" &FORMAT ( [Date], "ddmmyyyy" )& "-" &[Machine]This is the updated JSON:
{"data": {"name": "dataset"},"transform": [{"window": [{"op": "min", "field": "StartTime", "as": "ShiftStart"}],"groupby": ["ShiftID"]},{"calculate": "(datetime(datum.StartTime) - datetime(datum.ShiftStart)) / (1000 * 60 * 60)","as": "OffsetStart"},{// Similarly for EndTime"calculate": "(datetime(datum.EndTime) - datetime(datum.ShiftStart)) / (1000 * 60 * 60)","as": "OffsetEnd"}],"mark": "bar","encoding": {"y": {"field": "ShiftID", "type": "nominal"},"x": {"field": "OffsetStart","type": "quantitative","stack": null},"x2": {"field": "OffsetEnd"},"color": {"field": "Description", "type": "nominal"}}}- lbendlin1 year ago
Super User
Looks good. What else do you need?