javascript - R Shiny : setExtremes in Highcharts (rCharts) on page load

标签 javascript r highcharts shiny rcharts

我有一个 Shiny 的应用程序,它使用 rCharts 库来创建 Highcharts 图表。当应用程序首次启动时,我希望将应用程序放大到特定区域。

Highcharts 方法是 setExtremes() http://api.highcharts.com/highcharts#Axis.setExtremes

以下是可以在交互式 R 中运行的最小示例:

library(shiny)
library(rCharts)

runApp(list(
  ui = pageWithSidebar(
    headerPanel("title"),
    sidebarPanel('sidebar'),
    mainPanel(showOutput("testPlot", "Highcharts"))
  ),
  server = function(input, output, session) {
    output$testPlot <- renderChart2({
      hc <- Highcharts$new()
      hc$xAxis(categories=c('Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su',
                            'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa', 'Su'))
      hc$series(data=c(7, 1, 4, 2.5, 3.25, 2.875, 3.0625, 3, 3, 3, 3, 3, 3, 3))
      setX <- "#! function() {
                 var cht = this;
                 var chtXAxis = this.xAxis[0];
                 setTimeout(function() {
                   console.log(chtXAxis.getExtremes().max); // correctly shows 13 in the console
                   chtXAxis.setExtremes(2, 10);
                   console.log(chtXAxis.getExtremes().max); // nothing in the console
                   cht.showResetZoom();
                 }, 2000)
               } !#"
      hc$chart(type="spline", zoomType='xy', events=list(load=setX))

      hc$set(domID="testPlot")
      return(hc)
    })
  }
))

在控制台中可以看到getExtremes()方法成功了,但是setExtremes()方法不起作用。我不知道为什么。

任何人都可以帮助解决这个问题,或者就如何更好地在加载时设置极值提供建议吗?

最佳答案

Victorp 的回复表明我的代码没有任何根本问题,但 rCharts 确实很旧。如果您的 rCharts 版本比今天的版本更新,上面的代码应该可以工作,也许还有一些旧版本。我不知道我正在开发哪个版本,但它可能已经有几个月了。

感谢维克多普。

关于javascript - R Shiny : setExtremes in Highcharts (rCharts) on page load,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32459851/

相关文章:

javascript - 从各个模块获取单独的导出

javascript - 如何防止脚本更改 window.location 或在当前页面上重新加载?

r - 为重复的 POSIXct 日期添加一秒

javascript - HighCharts 错误 #18 : Requested Axis Does not exist

javascript - Highcharts 导出为 svg

javascript - 单击按钮时的 update_order_review( )

c# - 使用 WebAPI 的 Webforms C# 客户端验证 CustomValidator

r - 两个数据帧之间具有不同可变长度列的箱线图

r - 数据表 R 中的调色板

javascript - WpDatacharts(Highcharts 渲染)- 是否可以在加载时预先隐藏数据集?