Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
Hello ,
I am having a R-script visual in my report wherein, it has four columns of X- axis in a date/time format like (Shceduled start, Scheduled End , Actual Start and Actual End) which showcase the project scheduled start and end time with actual start and end time.
Our data connection mode is direct query for live data , as we all know direct query and r-script together have lot of limitations mentioned in the below documents like can use only limited functions and calculation exceeds timeout error etc...
Use DirectQuery in Power BI Desktop - Power BI | (microsoft.com)
Create Power BI visuals using R - Power BI | Microsoft Learn
In my report am facing very often slow performance issue and script time out error, so am looking for help to find a alternative visual which replace my current R-script visual.
In the above given visual my Y -axis defines the Project name, and the X-Axis defines the scheduled and Actual start and end time with colour code.
R script used
library(ggplot2)
library(scales) # For date_breaks and date_format
# Assuming 'dataset' is already loaded
# Convert time data
time_fields <- c("LocalScheduledStartTime", "LocalScheduledEndTime",
"LocalActualStartTime", "LocalActualEndTime")
for (field in time_fields) {
dataset[[field]] <- as.POSIXct(dataset[[field]], format = "%Y-%m-%dT%H:%M:%OS")
}
# Pre-compute colors to speed up the plot rendering
dataset$status_color <- with(dataset, ifelse(Status == "Completed-On Time", "#0DE018", # Green
ifelse(Status == "Completed-Delayed", "#FFA500", #orange
ifelse(Status == "In Progress - On Time", "#FFFF00", #Yellow
"#FF0000"))))# Red
# Pre-format PercentCompleted
dataset$PercentCompleted <- paste0(sprintf("%.0f", dataset$PercentCompleted), "%")
# Create the ggplot object
plot <- ggplot(dataset, aes(x = ScheduledStartTime, y = TaskName)) +
geom_segment(aes(x = ScheduledStartTime, y = TaskName,
xend = ScheduledEndTime, yend = TaskName),
size = 8, color = "#9F9D9D") + #Grey
geom_segment(aes(x = ActualStartTime, y = TaskName,
xend = ActualEndTime, yend = TaskName, color = status_color),
size = 6) +
scale_color_identity() + # To use the pre-computed colors directly
scale_x_datetime(date_breaks="01 hour", date_labels = "%H:%M") +
ggtitle("Title") +
xlab("") + ylab("") +
theme_bw() + # Apply a classic theme with default font size
theme(
axis.text.x = element_text(angle = -30, vjust = 1, hjust = 0),
axis.line = element_line(colour = "grey50",size =1 ),
axis.text = element_text(color = "black", size = 10),
plot.title = element_text(face = "bold", size = 12),
panel.grid.major = element_line(color = "grey70", size = 0.4),
panel.grid.minor = element_line(color = "grey70", size = 0.1))
# Print the plot
print(plot)
Sample Data
TaskName | ActualEndDateTime | ActualStartDateTime | ScheduledStartDateTime | ScheduledEndDateTime | Status |
A | 27-04-2024 09:16 | 27-04-2024 09:16 | 26-04-2024 23:30 | 27-04-2024 01:30 | Completed-Delayed |
B | 26-04-2024 19:36 | 26-04-2024 18:16 | 26-04-2024 18:15 | 26-04-2024 19:40 | Completed-On Time |
C | 27-04-2024 05:10 | 27-04-2024 04:38 | 26-04-2024 22:40 | 26-04-2024 23:30 | Completed-Delayed |
D | 27-04-2024 04:38 | 27-04-2024 02:59 | 26-04-2024 20:00 | 26-04-2024 22:10 | Completed-Delayed |
E | 26-04-2024 18:57 | 26-04-2024 18:48 | 26-04-2024 18:45 | 26-04-2024 19:15 | Completed-On Time |
F | 27-04-2024 05:57 | 27-04-2024 04:41 | 26-04-2024 22:15 | 26-04-2024 23:30 | Completed-Delayed |
Any alternate visual suggestion which suits my requirement will be a great help. As this R visual is slow in peformance after publishing to service and shows an error as Script execution timeout sometimes after published.
Note: Already tried Ghant chart but it will have only one start and one end time.
Thanks in Advance
Hi, I'm not sure about the double dates but the idea in general sounds like a Gantt graph. You could get custom visuals and try some Gantt chart. There are like 10 different ones.
I hope one of them might have want you need specifically here.
Happy to help!
Hi @ibarrau ,
I have tried gantt charts already and i couldnt find any gantt chart using four dates column, if you could help me finding the appropriate one it will be a great help.
Thanks!
Well if none of the many gantts available at the store let you build that visual, the only alternative would be the visuals that let you build inside, like html, deneb or d3js. Otherwise if you can't find anything that looks like the R visual, you might want to consider importing data or directlake (just in case you have or consider premium/fabric).
I hope that helps,
Happy to help!