具体使用参考:
调用方法
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
end
end
调用方法
<%=high_chart_ajax("dom_name", @highcharts) %>