一个用于生成图表的gem: lazy_high_charts

来源:互联网 发布:美食做法软件 编辑:程序博客网 时间:2024/05/16 04:17
具体使用参考:

https://github.com/michelson/lazy_high_charts


但是它不提供ajax加载的图标方式

因为生成的js代码,实在 window.onload方法中运行的

怎么办?

增加新的ajax 代码

# -*- encoding: utf-8 -*- module LazyHighCharts  module LayoutHelper    def high_chart_ajax(placeholder, object, &block)      object.html_options.merge!({:id=>placeholder})      object.options[:chart][:renderTo] = placeholder      high_graph_ajax(placeholder,object , &block).concat(content_tag("div","", object.html_options))    end    def high_graph_ajax(placeholder, object, &block)      build_ajax_html_output("Chart", placeholder, object, &block)    end    def build_ajax_html_output(type, placeholder, object, &block)      options_collection = [ generate_json_from_hash(object.options) ]      options_collection << %|"series": #{object.data.to_json}|      graph =<<-EOJS        <script type="text/javascript">        var options, chart;        options = { #{options_collection.join(',')} };        #{capture(&block) if block_given?}        chart = new Highcharts.#{type}(options);        </script>      EOJS      if defined?(raw)        return raw(graph)      else        return graph      end    end  endend

调用方法
<%=high_chart_ajax("dom_name", @highcharts)  %>



原创粉丝点击