问题
Hi So what i'd like to be able to do is make all the ranges which contain open appear say "red" and Staff meeting appear blue. Is it possible to do this, could only see documentation on changing the colour based off the group. I know I can use style to change the text but that only changes the colour of the text inside the box and not the background shading of the box.
library(timevis)
# Data for groups example
dataGroups <- data.frame(
id = 1:11,
content = c("Open", "Open",
"Open", "Open", "Half price entry",
"Staff meeting", "Open", "Adults only", "Open", "Hot tub closes",
"Siesta"),
start = c("2016-05-01 07:30:00", "2016-05-01 14:00:00",
"2016-05-01 06:00:00", "2016-05-01 14:00:00", "2016-05-01 08:00:00",
"2016-05-01 08:00:00", "2016-05-01 08:30:00", "2016-05-01 14:00:00",
"2016-05-01 16:00:00", "2016-05-01 19:30:00",
"2016-05-01 12:00:00"),
end = c("2016-05-01 12:00:00", "2016-05-01 20:00:00",
"2016-05-01 12:00:00", "2016-05-01 22:00:00", "2016-05-01 10:00:00",
"2016-05-01 08:30:00", "2016-05-01 12:00:00", "2016-05-01 16:00:00",
"2016-05-01 20:00:00", NA,
"2016-05-01 14:00:00"),
group = c(rep("lib", 2), rep("gym", 3), rep("pool", 5), NA),
type = c(rep("range", 9), "point", "background")
)
groups <- data.frame(
id = c("lib", "gym", "pool"),
content = c("Library", "Gym", "Pool")
)
timevis(data = dataGroups, groups = groups)
回答1:
you need to do something like this:
tags$head(
tags$style(HTML(".vis-item.blah { color: black; background-color: #1ac6ff; border-color: #1ac6ff; }"))
where .blah is an items className
来源:https://stackoverflow.com/questions/54885083/timevis-make-different-boxes-have-colour-dependent-on-name-in-different-groups