【问题标题】:R Highcharter zoom selected areaR Highcharter 缩放选定区域
【发布时间】:2018-02-19 10:30:47
【问题描述】:

是否可以使用闪亮的应用程序将缩放区域的坐标存储在 highcharter 中?

我想要类似example's:

function getSelection(event) {
    alert(event.xAxis[0].min);
    alert(event.xAxis[0].max);
} 

但不是警报,只是为了存储和使用它们。

闪亮的应用示例:

library(shiny)
library(dplyr)
library(highcharter)
library(tidyr)

df_plot <- cbind(
  seq(0, 1, by = 0.1),
  sample(seq(from = 100, to = 300, by = 10), size = 11, replace = TRUE),
  sample(seq(from = 1, to = 100, by = 9), size = 11, replace = TRUE),
  sample(seq(from = 50, to = 60, by = 2), size = 11, replace = TRUE),
  sample(seq(from = 100, to = 130, by = 1), size = 1, replace = TRUE)
) %>% as.data.frame()

names(df_plot) <- c("x", "a", "b", "c", "d")


ui <- fluidPage(
  column(
    width = 3,
    selectInput("select", "Select var:", choices = c("a", "b", "x", "y"), selected = c("a", "b", "x"), multiple = TRUE)
  ),
  column(
    width = 9
  ),
  column(
    width = 12,
    highchartOutput("plot")
  )
)

server <-  function(input, output){

  output$plot <- renderHighchart({
    highchart() %>%
      hc_xAxis(categories = df_plot$x) %>%
      hc_add_series(data = df_plot$a) %>%
      hc_add_series(data = df_plot$b, yAxis = 1) %>%
      hc_yAxis_multiples(
        list(lineWidth = 3, lineColor='#7cb5ec', title=list(text="First y-axis")),
        list(lineWidth = 3, lineColor="#434348", title=list(text="Second y-axis"))) %>%
      hc_chart(
        zoomType = "x"
      )
  })
}

shinyApp(ui, server)

【问题讨论】:

    标签: r shiny r-highcharter


    【解决方案1】:

    你可以这样做:

    library(shiny)
    library(highcharter)
    
    
    ui <- fluidPage(
      column(8,highchartOutput("hcout")),
      column(4,textOutput("eventout"))
      )
    
    server <- function(input, output) {
    
       output$hcout <- renderHighchart({
    
         highcharts_demo() %>% 
           hc_chart(
             zoomType = "xy",
             events = list(
               selection = JS("function(event) {
                            Shiny.onInputChange('event', [event.xAxis[0].min,     event.xAxis[0].max]);
                              return true;
                              } ")
             )
           ) 
    
       })
    
       output$eventout <- renderText({ 
    
         input$event
         })
    
    }
    

    但我不知道为什么 reset zoom 按钮不起作用(与启用 resetZoomButton 时的 jsfiddle 示例相同)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-21
      • 2021-03-23
      • 2016-09-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-01
      • 2010-11-13
      • 2013-04-12
      相关资源
      最近更新 更多