DataLabels in R highcharter cannot be seen after print as png or jpg

家住魔仙堡 提交于 2020-07-25 03:50:33

问题


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)

This is chart in viewer an html:

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...


回答1:


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.

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")

Code

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)

The png file (hc.png)



来源:https://stackoverflow.com/questions/61347676/datalabels-in-r-highcharter-cannot-be-seen-after-print-as-png-or-jpg

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!