How to set highchart global options IN R

后端 未结 3 1382
滥情空心
滥情空心 2021-01-17 03:25

I see a lot of examples in javascript but I cannot find an example to do it in R

Here is the api link: http://api.highcharts.com/highcharts#global

I am tryin

相关标签:
3条回答
  • 2021-01-17 03:41

    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)
    
    0 讨论(0)
  • 2021-01-17 03:44

    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.

    0 讨论(0)
  • 2021-01-17 03:56

    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.

    0 讨论(0)
提交回复
热议问题