How to set highchart global options IN R

被刻印的时光 ゝ 提交于 2019-12-01 13:59:46

The highcharter options can be accessed, but they are set inside the standard R options under the list element highcharter.options. They are not given directly to the highchart, and inside highchart(), there is the code line opts <- getOption("highcharter.options", list()).

I don't think there is another way than just get the options, alter whatever options you need to change and then set the options again with your additions.

The following is a simple illustration:

library(highcharter)

# normal highchart
highchart() %>%
  hc_add_serie_labels_values(1:901, seq(1, 10, 0.01))

opts <- getOption("highcharter.options")
opts$lang$decimalPoint <- "."
options(highcharter.options = opts)

# now with "," instead of "." (confirm in tooltip)
highchart() %>%
  hc_add_serie_labels_values(1:901, seq(1, 10, 0.01))

Of course in your case, you need to set the $global$timezoneOffset part.

As of version 0.5.0 of highcharter, it seems the option highcharter.options is not there any more, but there are several separate options, e.g. highcharter.lang, highcharter.global, etc. So the following approach works:

lang <- getOption("highcharter.lang")
lang$decimalPoint <- ","
lang$numericSymbols <- highcharter::JS("null") # optional: remove the SI prefixes
options(highcharter.lang = lang)

In addition to changing the decimal point, the SI prefixes ("k", "M", "G", etc.) are turned off by setting the numericSymbols to null, see Replacing/removing the metric notations like thousands "k" abbreviation.

First you have to switch of the useUTC flag to FALSE. Than you can set the timezoneOffset as you wish and save the options back.

global <- getOption("highcharter.global")
global$useUTC <- FALSE
global$timezoneOffset <- -300
options(highcharter.global = global)

For better understanding make sure you take a look at global:

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