经过SetExtremes回调for highcharts [英] afterSetExtremes callback for highcharts

查看:553
本文介绍了经过SetExtremes回调for highcharts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用lazy_highcharts gem创建了一张高图。我想利用afterSetExtremes回调来重新生成缩放页面上的一些其他数据。我尝试了几种方法,目前正在尝试:

I'm creating a highchart using the lazy_highcharts gem. I'd like to make use of the afterSetExtremes callback to regenerate some other data on the page on zooming. I've tried several ways, currently trying:

 @chart = LazyHighCharts::HighChart.new('graph') do |f|
                    f.chart(:zoomType =>'x', :defaultSeriesType => 'spline')
                    f.x_axis(:type=> 'datetime', :events => {:afterSetExtremes => "functon(event){alert('something')}"} )
end

但是,这给了我错误

But that gives me the error

Uncaught TypeError: Object functon(event){alert('something')} has no method 'apply'

。我认为这与发生器没有正确设置回调函数有关,它将其设置为一个字符串,而不是将其解释为函数。

in the javascript console when I zoom the chart. I assume this has something to do with the generator not correctly setting up the callback function, setting it as a string instead of interpreting it as a function.

我也是试图在创建后通过javascript将其设置在我的图表对象上,但到目前为止没有运气。

I've also tried to set it on my chart object via javascript after creation, but so far have had no luck with that. A few attempts below

chart_my_id4.xAxis.events = {setExtremes: function(event) {
      alert('set extremes');
    }};
chart_my_id4.xAxis[1].events = {setExtremes: function(event) {
      alert('set extremes');
    }};

没有运气。

任何深入了解,谢谢。

推荐答案

不太熟悉... ruby​​,但我看了一下github上的源代码他们在将属性设置为属性时执行以下操作:

Not too familiar with ... ruby, but I took a look at the source on github and they do the following when they set functions into attributes:

:formatter => "function() { return this.x; }".js_code

值得一试添加.js_code并查看它是否有效,最终得到:

It would be worth a try to add that .js_code and see if it works so you end up with:

 @chart = LazyHighCharts::HighChart.new('graph') do |f|
   f.chart(:zoomType =>'x', :defaultSeriesType => 'spline')
   f.x_axis(:type=> 'datetime', :events => {
     :afterSetExtremes => "functon(event){alert('something')}".js_code
   })
end

这篇关于经过SetExtremes回调for highcharts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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