How can I create a single row gantt chart e.g. to display the state of a machine?
At the moment there is no "gantt chart" widget which you can choose, but with a little trick and some data preparation you can create a chart which looks like the one shown below:
So how can you create this chart?
This is an "Area chart" with "Step Area" as line type and a series for each type of state. To make this working correct the input data has to be in a special format. To understand this format easily we will describe it for the simple example shown below:
The input data has 5 columns. One for the timestamp of the state change and one for each state type. For each observation/row in the data only one of these state type columns is allowed to have value 1. All other columns have to have value 0. This is to avoid overlaps. Value 1 means that the state of the machine changed to this state. For example row 3 shows that at timestamp "2019-05-07 12:05:20" the state changed to "warning".
To get input data in this format you could either use an Analytics Query with calculated columns (if you have explicit state information) or you can also use the functions which are presented in the article "Set operations on time interval information (like alarms, warnings etc.)" (if you have implicit state information).
Using implicit state information:
If you have only implicit information on the machine state like alarm messages with start and stop times you can use the set operation functions in combination with the following code snippet.
Where the data frame 'df' contains the interval informations (category, start, stop) with three different categories where "e" stands for error, "w" stands for warning and "i" stands for information. In this code snipped we calculated the non-overlapping periods with the given priorization and assumed that if there is no error, warning or information the machine is ok.
# ----- Calculations ---- periods <- nonoverlapping_periods(df, prio = c("e","w","i")) event_list <- periods2events(periods) %>% select(-parallels) %>% mutate( category = as.character(category), error = ifelse(category == "e" & edge == 1, 1, 0), warning = ifelse(category == "w" & edge == 1, 1, 0), info = ifelse(category == "i" & edge == 1, 1, 0), ok = ifelse(error == 0 & warning == 0 & info == 0, 1, 0)) timestamp <- as.character(as.POSIXct(event_list$timestamp/1000, origin = "1970-01-01")) error <- event_list$error warning <- event_list$warning info <- event_list$info ok <- event_list$ok