我在 Highcharter 中有几个柱形图可以向下钻取。我注意到,根据列钻取的大小,highcharter 从显示正确的 x 轴名称切换到索引。有什么方法可以确保它始终显示 x 轴名称?
下面是一个示例代码,显示了正确显示和不正确显示的场景。唯一的变化是数据集的大小(从 400 到 50)。
library (highcharter)
rm(list=ls())
#### CASE 1 - X AXIS NAMES NOT SHOWING IN DRILLDOWN ####
h <- 0
Case1Num <- c()
for(i in 1:400){
h <- h + .02
Case1Num[i] <- h
}
Case1Name <- c()
for(i in 1:400){
Case1Name[i] <- paste0("test",i)
}
Case1Group <- c()
for(i in 1:400){
Case1Group[i] <- paste0("group1")
}
Case1 <- data.frame(Case1Name,Case1Num,Case1Group)
Lvl1 <- aggregate(Case1$Case1Num, by = list(Case1$Case1Group),FUN=sum)
Lvl1df <- data_frame(name = Lvl1$Group.1, y = Lvl1$x, drilldown = tolower((paste(name))))
dfLvl2 <- arrange(data_frame(name = Case1$Case1Name,value = Case1$Case1Num),desc(value))
hc <- highchart() %>%
hc_chart(type = "column", zoomType = "x") %>%
hc_xAxis(type = "category", labels = list(style = list(fontSize = "1.1vh"))) %>%
hc_yAxis(gridLineWidth = 0, labels = list(style = list(fontSize = "1.1vh"))) %>%
hc_add_series(data=Lvl1df, color = "#D20000") %>%
hc_legend(enabled = TRUE) %>%
hc_plotOptions(column = list(stacking = "normal")) %>%
hc_drilldown(
allowPointDrilldown = TRUE,
series = list(
list(id = "group1", data = list_parse2(dfLvl2))
)
)
hc
#### CASE 2 - X AXIS NAMES SHOWING CORRECTLY IN DRILLDOWN ####
h <- 0
Case2Num <- c()
for(i in 1:50){
h <- h + .02
Case2Num[i] <- h
}
Case2Name <- c()
for(i in 1:50){
Case2Name[i] <- paste0("test",i)
}
Case2Group <- c()
for(i in 1:50){
Case2Group[i] <- paste0("group1")
}
Case2 <- data.frame(Case2Name,Case2Num,Case2Group)
Lvl1 <- aggregate(Case2$Case2Num, by = list(Case2$Case2Group),FUN=sum)
Lvl1df <- data_frame(name = Lvl1$Group.1, y = Lvl1$x, drilldown = tolower((paste(name))))
dfLvl2 <- arrange(data_frame(name = Case2$Case2Name,value = Case2$Case2Num),desc(value))
hc2 <- highchart() %>%
hc_chart(type = "column", zoomType = "x") %>%
hc_xAxis(type = "category", labels = list(style = list(fontSize = "1.1vh"))) %>%
hc_yAxis(gridLineWidth = 0, labels = list(style = list(fontSize = "1.1vh"))) %>%
hc_add_series(data=Lvl1df, color = "#D20000") %>%
hc_legend(enabled = TRUE) %>%
hc_plotOptions(column = list(stacking = "normal")) %>%
hc_drilldown(
allowPointDrilldown = TRUE,
series = list(
list(id = "group1", data = list_parse2(dfLvl2))
)
)
hc2
看起来这个问题已经在 github 线程中解决了。
添加cropThreshold = 1000
来hc_plotOptions
解决这个问题。它通常设置为默认值,50
这就是为什么上面看到的更大的原因。
hc2 <- highchart() %>%
hc_chart(type = "column", zoomType = "x") %>%
hc_xAxis(type = "category", labels = list(style = list(fontSize = "1.1vh"))) %>%
hc_yAxis(gridLineWidth = 0, labels = list(style = list(fontSize = "1.1vh"))) %>%
hc_add_series(data=Lvl1df, color = "#D20000") %>%
hc_legend(enabled = TRUE) %>%
hc_plotOptions(column = list(
cropThreshold = 1000,
stacking = "normal")) %>%
hc_drilldown(
allowPointDrilldown = TRUE,
series = list(
list(id = "group1", data = list_parse2(dfLvl2))
)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句