2016-11-04 92 views
0

我正在使用highcharter軟件包繪製R-Shiny項目的財務日內時間系列。爲了得到輸出我使用的服務器部分下面的代碼(注意,xtsPrices()是返回XTS盤中時,意甲功能):我的文檔中讀取R Shiny Highcharter - 如何使用hc_rangeSelector()

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

,在爲了個性化縮放按鈕,我必須處理hc_rangeSelector()函數,但我不明白如何在這個R-Shiny環境中指定它們,如Highstock API中的javascript案例所示。特別是 - 因爲它是一個日間時間系列 - 我需要像「20分鐘」,「1小時」,「3小時」,「1D」等按鈕。

+0

這個問題可以幫助你http://stackoverflow.com/questions/39665958/how-do-i-adjust-the-initial-range-in-hc-navigator/ 39666504#39666504。您需要'highcharts(type =「stock」)%>%'以瞭解rangeSelector中的選項,請訪問http://api.highcharts.com/highstock/rangeSelector。希望這可以幫助 – jbkunst

回答

0

對於日內數據,您可以做類似這樣的:

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 

enter image description here

+1

完美,這正是我需要的!非常感謝! –

+0

Np,很高興幫助!你應該提供樣本數據,下一次我必須查詢我的數據庫來製作情節 –