简体   繁体   English

R Shiny Highcharter - 如何使用hc_rangeSelector()

[英]R Shiny Highcharter - How to use hc_rangeSelector()

I'm plotting a financial intra-day time serie on an R-Shiny project using the highcharter package. 我正在使用highcharter软件包在R-Shiny项目上绘制一个金融日内时间系列。 I'm using the following code for the server part in order to get the output (note that xtsPrices() is a function that returns an xts intraday time-serie): 我正在使用以下代码作为服务器部分以获取输出(请注意,xtsPrices()是一个返回xts intraday time-serie的函数):

output$plot <- renderHighchart({

y <- xtsPrices()

highchart() %>%
  hc_exporting(enabled = TRUE)%>%
  hc_add_series_ohlc(y) %>% 
  hc_add_theme(hc_theme_538(colors = c("red", "blue", "green"),
                            chart = list(backgroundColor = "white") ))
})

I read in the documentation that in order to personalize zoom buttons I have to deal with the hc_rangeSelector() function, but I don't understand how to specify them in this R-Shiny environment as shown for the javascript case in Highstock API . 我在文档中读到,为了个性化缩放按钮,我必须处理hc_rangeSelector()函数,但我不明白如何在这个R-Shiny环境中指定它们,如Highstock API中的javascript案例所示。 In particular - because it's an intra-day time-serie - I would need buttons like "20min", "1h", "3h", "1D", etc. 特别是 - 因为它是一个日内时间系列 - 我需要按钮,如“20分钟”,“1小时”,“3小时”,“1D”等。

For intra-day data you can do something like this: 对于日内数据,您可以执行以下操作:

hc <- highchart() %>% 
  hc_exporting(enabled = TRUE) %>%
  hc_add_series_ohlc(y, yAxis = 0, name = "Sample Data", id = "T1",smoothed=TRUE,forced=TRUE,groupPixelWidth=24) %>% 
  hc_rangeSelector( buttons = list(
    list(type = 'all', text = 'All'),
    list(type = 'hour', count = 2, text = '2h'),
    list(type = 'hour', count = 1, text = '1h'),
    list(type = 'minute', count = 30, text = '30m'),
    list(type = 'minute', count = 10, text = '10m'),
    list(type = 'minute', count = 5, text = '5m')
  )) %>% 
  hc_add_theme(hc_theme_538(colors = c("red", "blue", "green"),chart = list(backgroundColor = "white") ))
hc

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM