3

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

我想要类似于这个例子的东西:

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)
4

1 回答 1

5

你可以这样做:

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按钮不起作用(与启用时的 jsfiddle 示例相同resetZoomButton

于 2017-09-11T17:29:36.487 回答