2

我正在使用lazy_high_chartsfoundation 4

在我看来,我有<%= high_chart("my_id", @chart) %>,它会生成以下内容:

<section>
  <script type="text/javascript">
    (function() {
      var onload = window.onload;                      # I think
      window.onload = function(){                      # the issue
        if (typeof onload == "function") onload();     # is here
          var options = { "title": { "text": "Combination chart" },"legend": { "layout": "vertical","style": {  } },"xAxis": {  },"yAxis": { "title": { "text": null },"labels": {  } },"tooltip": { "enabled": true },"credits": { "enabled": false },"plotOptions": { "areaspline": {  } },"chart": { "defaultSeriesType": "line","renderTo": "my_id" },"subtitle": {  },"series": [{ "type": "spline","name": "Average","data": [ 3,2.67,3,6.33,3.33 ] }] };

    window.chart_my_id = new Highcharts.Chart(options);

      };
    })()
  </script>
<div id="my_id"></div>
</section>

但是,由于foundation 4在我的application.js

$(document).foundation();
$(function(){ $(document).foundation(); });

如果我删除这些线,图表就会加载。

我怎样才能使用foundationlazy_high_charts在一起?

4

2 回答 2

1

我解决了更新zurb-foundationlazy_high_charts宝石的问题:

在我的 Gemfile 中:

gem 'zurb-foundation', '~> 4.0.0'
gem 'lazy_high_charts'

然后:

bundle install
bundle update lazy_high_charts
rails g foundation:install

我还在以下行中包含了application.html.erb

  ...
  <%= javascript_include_tag "vendor/custom.modernizr" %>
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  ...

之后,<%= high_chart("my_id", @chart) %>代码将生成以下 javascript:

<script type="text/javascript">        
(function() {
  var f = function(){
  document.removeEventListener('page:load', f, true);
...

我希望它可以帮助面临同样问题的人。

于 2013-08-28T09:00:20.477 回答
1

代替

(function() {
var onload = window.onload;                      # I think
window.onload = function(){                      # the issue

$(function(){

生成的脚本标记将如下所示:

<section>
  <script type="text/javascript">
        $(function() {
          var options = { "title": { "text": "Combination chart" },"legend": { "layout": "vertical","style": {  } },"xAxis": {  },"yAxis": { "title": { "text": null },"labels": {  } },"tooltip": { "enabled": true },"credits": { "enabled": false },"plotOptions": { "areaspline": {  } },"chart": { "defaultSeriesType": "line","renderTo": "my_id" },"subtitle": {  },"series": [{ "type": "spline","name": "Average","data": [ 3,2.67,3,6.33,3.33 ] }] };

    window.chart_my_id = new Highcharts.Chart(options);

    });
  </script>
<div id="my_id"></div>
</section>

确保在它之前放置了 jquery 脚本。

于 2013-08-25T14:34:46.407 回答