R中的Highcharter setExtremes函数 [英] Highcharter setExtremes Function in R

查看:98
本文介绍了R中的Highcharter setExtremes函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在与用户按下按钮相对应的时间序列股票图表上设置极端值.这是细分:

I'm trying to set extremes on a time series stock chart that corresponds to a user pushing a button. Here's the breakdown:

  1. 用户单击图表顶部的按钮(我通常在顶部编辑了全部","1M","3M"按钮)

  1. User clicks on a button on the top of the chart (I have edited the "All", "1M", "3M" buttons typically at the top)

单击该按钮,将放大xAxis(2个月)上的自定义区域.例如,10月1日至12月1日.现在,缩放到图表的末尾.

When the button is clicked, a custom area on the xAxis (2 months) is zoomed in on. For example, October 1st through December first. Right now, the zoom goes to the end of the graph.

它与下面的链接非常相​​似.

It's very similar to the below link.

X轴设置极限值

我现在在按钮上的R代码如下:

X Axis Set Extremes

My R code right now for the button is the following:

hc_rangeSelector(buttons=list(list(type='month', text='New', count=2)))

这表示我正在寻找一个月间隔缩放,文本为"New",它显示2个月.我已经看到setExtremes是我正在寻找的功能,但我还没有看到它是使用R实现的.

This says I am looking for a month interval zoom, the text is "New", and it shows 2 months. I've seen that setExtremes is the function i'm looking for but I haven't seen it implemented using R.

推荐答案

您可以在Highcharter的chart.events.load选项中放置一个JavaScript函数.使用渲染器,您可以添加将使用

You could place a JavaScript function in chart.events.load option in Highcharter. Using Renderer you could add a button that will use setExtremes function on click.

JSFiddle中的演示(没有Highcharter或`R,数据不同,但是按钮的功能相同):

Demo in JSFiddle (without Highcharter nor `R, data is different, but functionality of the button is the same): http://jsfiddle.net/e69eLm6q/

要在R中运行的代码:

library("quantmod")

usdjpy <- getSymbols("USD/JPY", src = "oanda", auto.assign = FALSE)
eurkpw <- getSymbols("EUR/KPW", src = "oanda", auto.assign = FALSE)

hc <- highchart(type = "stock") %>% 
  hc_title(text = "Charting some Symbols") %>% 
  hc_add_series(data = usdjpy, id = "usdjpy", pointInterval = 36000000) %>% 
  hc_add_series(data = eurkpw, id = "eurkpw", pointInterval = 36000000) %>%
  hc_rangeSelector(buttons=list(list(type='month', text='New', count=2))) %>%
  hc_chart(
    events = list(
        load = JS("function(){
            var chart = this;

            chart.renderer.button('do stuff',200, 100)
                .attr({
                    zIndex: 3
                })
                .on('click', function () {
                    chart.xAxis[0].setExtremes(Date.UTC(1970, 4, 1), Date.UTC(1970, 6, 1));
                })
                .add();
        }")
    )
  )

hc

这篇关于R中的Highcharter setExtremes函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆