问题描述
我正在尝试打印我的图表图表.
I'm trying to print my highchartrer chart.
library(highcharter)
webshot::install_phantomjs()
colors_ <- colorize(1:6, c("#FFA500", "#000000"))
df <- data.frame(y = round(rnorm(5, 10, 2), digits = 1),
name = paste0("Name", c(1:5)),
color = colors_[1:5])
hc <- highchart() %>%
hc_chart(type = "column") %>%
hc_xAxis(categories = df$name) %>%
hc_add_series(
df,
dataLabels = list(
enabled = T,
shadow = F,
color = "black",
style = list(
textShadow = F,
textOutline = F,
fontWeight = 'normal',
opacity = 1
)
)
)
htmlwidgets::saveWidget(widget = hc, file = "hc.html")
webshot::webshot(url = "hc.html", file = "hc.png", delay = 1, zoom = 4, vheight = 500)
这是查看器中的HTML图表:
This is chart in viewer an html:
这是png或jpg:
And this is png or jpg:
有标签,但非常透明.我尝试了不同的风格.没有成功.你能帮忙吗?
There are labels, but very transparent. I tried different styles. Without success. Can you help?
installed.packages():Highcharter,htmlwidgets,webshot ...
installed.packages(): highcharter, htmlwidgets, webshot...
推荐答案
您应该考虑在webshot2 而不是使用webshot /webshot2"rel =" nofollow noreferrer> https://github.com/rstudio/webshot2 ,不会受到此问题的困扰.我已经用webshot2复制了您的方案,该问题已解决,如下图所示.
Instead of using webshot, you should consider to try webshot2 on https://github.com/rstudio/webshot2 which doesn't suffer from this issue. I have replicated your scenario with webshot2, the issue is resolved as below screenshot.
注意:在尝试安装webshot2软件包之前,请不要忘记删除websot.为了删除它,请转到Rstudio右下角的Packages,搜索该包的名称,然后单击相邻的X图标将其删除,或者您可以通过Rstudio控制台以这种方式处理它:
Note: Before trying to install webshot2 package, do not forget to remove websot. In order to remove it, go to the Packages in right bottom corner of Rstudio, sear the package name and click on the adjacent X icon to remove it or you I handle it in this way from the Rstudio console:
remove.packages("webshot", lib="~/R/win-library/3.6")
代码
library(highcharter)
library(webshot2)
colors_ <- colorize(1:6, c("#FFA500", "#000000"))
df <- data.frame(y = round(rnorm(5, 10, 2), digits = 1),
name = paste0("Name", c(1:5)),
color = colors_[1:5])
hc <- highchart() %>%
hc_chart(type = "column") %>%
hc_xAxis(categories = df$name) %>%
hc_add_series(
df,
dataLabels = list(
enabled = T,
shadow = F,
color = "black",
style = list(
textShadow = F,
textOutline = F,
fontWeight = 'normal',
opacity = 1
)
)
)
htmlwidgets::saveWidget(widget = hc, file = "hc.html")
webshot(url = "hc.html", file = "hc.png", delay = 1, zoom = 4, vheight = 500)
png文件(hc.png)
这篇关于打印为png或jpg后,无法看到R highcharter中的DataLabels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!