[英]Highcharter setExtremes Function in R
I'm trying to set extremes on a time series stock chart that corresponds to a user pushing a button.我试图在对应于用户按下按钮的时间序列股票图表上设置极端。 Here's the breakdown:
这是细分:
User clicks on a button on the top of the chart (I have edited the "All", "1M", "3M" buttons typically at the top)用户点击图表顶部的按钮(我已经编辑了通常位于顶部的“全部”、“1M”、“3M”按钮)
When the button is clicked, a custom area on the xAxis (2 months) is zoomed in on.单击该按钮时,xAxis(2 个月)上的自定义区域会放大。 For example, October 1st through December first.
例如,从 10 月 1 日到 12 月。 Right now, the zoom goes to the end of the graph.
现在,缩放到图形的末尾。
It's very similar to the below link.它与下面的链接非常相似。
My R code right now for the button is the following:我现在按钮的 R 代码如下:
hc_rangeSelector(buttons=list(list(type='month', text='New', count=2)))
This says I am looking for a month interval zoom, the text is "New", and it shows 2 months.这说我正在寻找一个月间隔缩放,文本是“新”,它显示 2 个月。 I've seen that setExtremes is the function i'm looking for but I haven't seen it implemented using R.
我已经看到 setExtremes 是我正在寻找的函数,但我还没有看到它使用 R 实现。
You could place a JavaScript function in chart.events.load option in Highcharter
.您可以在
Highcharter
chart.events.load 选项中放置一个 JavaScript 函数。 Using Renderer you could add a button that will use setExtremes function on click.使用Renderer,您可以添加一个按钮,该按钮将在单击时使用setExtremes函数。
Demo in JSFiddle (without Highcharter
nor `R, data is different, but functionality of the button is the same): http://jsfiddle.net/e69eLm6q/ JSFiddle中的Demo(没有
Highcharter
和`R,数据不同,但是按钮的功能是一样的): http : //jsfiddle.net/e69eLm6q/
Code to run in R
:在
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.