问题描述
我正在使用 dataui 包来创建迷你图。我希望对角线填充的颜色与迷你图的颜色相匹配。
因此,A 公司将有一条绿线,下方有绿色对角线填充,B 公司将有一条红线,下方有红色对角线填充。
我似乎无法让对角线填充具有多个值。
这可能吗?
library("tidyverse")
library("dataui")
library("reactable")
df <- tibble(
Company = c("A","B"),Line = list(list(c(1,2,1)),list(c(2,1)))
)
colpal <- c("#00DA07","#BB0337")
rt1 <- reactable(df,compact = TRUE,fullWidth = FALSE,columns = list(
Line = colDef(
cell = function(value,index) {
dui_sparkline(
data = value[[1]],height = 80,components = list(
dui_sparklineseries(
curve = "linear",showArea = TRUE,fill = "url(#area_pattern2)",stroke = colpal[index]),# Diagonal fill lines
dui_sparkpatternlines(
id = "area_pattern2",height = 4,width = 4,stroke = colpal[index],strokeWidth = 1,orientation = "diagonal"
)
)
)
}
)
)
)
rt1
解决方法
library("tidyverse")
library("dataui")
library("reactable")
df <- tibble(
Company = c("A","B"),Line = list(list(c(1,2,1)),list(c(2,1)))
)
colpal_fill <- c("url(#area_pattern2)","url(#area_pattern3)")
colpal_stroke <- c("#91a7ff","#F1a0ff")
rt1 <- reactable(df,compact = TRUE,fullWidth = FALSE,columns = list(
Line = colDef(
cell = function(value,index) {
dui_sparkline(
data = value[[1]],height = 80,margin = list(top = 20,right = 20,bottom = 20,left = 20),components = list(
dui_sparkpatternlines(
id = "area_pattern2",height = 4,width = 4,stroke = "#91a7ff",strokeWidth = 1,orientation = "diagonal"
),dui_sparkpatternlines(
id = "area_pattern3",stroke = "#F1a0ff",dui_sparklineseries(
curve = "linear",showArea = TRUE,fill = colpal_fill[index],stroke = colpal_stroke[index]
)
)
)
}
)
)
)
rt1