0

http://www.highcharts.com/demo/column-basic/skiesの手順に従いました。問題は、コントローラーからハイチャート グラフィックへの値が空白で表示されている (値が表示されていない) ことです。

ここで、コントローラーで使用するテーブル http://sqlfiddle.com/#!2/b7347/5

|policies|
  ID     POLICY_NUM    DATE_INI  CATEGORY_ID
   1       1234      2013-01-10     1
   2       5678      2013-01-10     2
   3       3444      2013-02-10     1
   4       4577      2013-02-10     2

|categories|
  ID   NAME
  1    Life
  2    Vehicles

これが私のコントローラーです

def report

  @jan_life =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 1 AND date_ini BETWEEN '2013-01-01' AND '2013-01-31'")

  @jan_vehi =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 2 AND date_ini BETWEEN '2013-01-01' AND '2013-01-31'")

  @feb_life =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 1 AND date_ini BETWEEN '2013-02-01' AND '2013-02-28'")

  @feb_vehi =Policy.find_by_sql("select count(*) as total from policies Inner join categories ON categories.id =category_id WHere category_id = 2 AND date_ini BETWEEN '2013-02-01' AND '2013-02-28'")

end

これが私の見解です

##### To Disable prototype #####
<script type="text/javascript">Array.prototype.reduce = undefined;</script>

##### To show High Chart Code ####
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

##### Values from my controller , actually is working ####
    <%= @jan_life[0].try(:total) %>     #it shows 1 value according with the info
    <%= @jan_vehi[0].try(:total) %>     #it shows 1 value according with the info
    <%= @feb_life[0].try(:total) %>     #it shows 1 value according with the info
    <%= @feb_vehi[0].try(:total) %>     #it shows 1 value according with the info

#### This code is HighChart image ####
<script src="http://code.highcharts.com/highcharts.js"></script>
<script src="http://code.highcharts.com/modules/exporting.js"></script>

<div id="container" style="min-width: 310px; height: 400px; margin: 0 auto"></div>

<script type="text/javascript">
 $(function () {
    $('#container').highcharts({
        chart: {
            type: 'column'
        },
        title: {
            text: 'Monthly Average Rainfall'
        },
        subtitle: {
            text: 'Source: WorldClimate.com'
        },
        xAxis: {
            categories: [
                'Jan',
                'Feb'    
            ]
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Rainfall (mm)'
            }
        },
        tooltip: {
            headerFormat: '<span style="font-size:10px">{point.key}</span><table>',
            pointFormat: '<tr><td style="color:{series.color};padding:0">{series.name}: </td>' +
                '<td style="padding:0"><b>{point.y:.1f} mm</b></td></tr>',
            footerFormat: '</table>',
            shared: true,
            useHTML: true
        },
        plotOptions: {
            column: {
                pointPadding: 0.0,
                borderWidth: 0
            }
        },
        series: [{
            name: 'Life',
            data: @jan_life[0].try(:total) %>,

        } , {
            name: 'Vehicles',
            data: @feb_life[0].try(:total) %>

        }]
    });
});
  </script>    

私が間違っていることは何ですか?空白が表示されています パラメータを渡していないようです

http://jsfiddle.net/ajEF2/が必要なハイチャート コード ビューを次に示します。

しかし、値を書きたくないので、コントローラーからの値を使用してレポート画像に表示したい

誰かがこれで私を助けることができますか?

私は本当に助けに感謝します

4

1 に答える 1

1

いくつかのこと:

<%=1.)データ割り当てに次のものがありませんか:

    series: [{
        name: 'Life',
        data: **<%=** @jan_life[0].try(:total) %>,

    } , {
        name: 'Vehicles',
        data: **<%=** @feb_life[0].try(:total) %>

    }]

2.) レールを作成してからしばらく経ちましたが<%= @feb_life[0].try(:total) %>、単一の値が生成されませんか? 最終的には次のようになります。

    series: [{
        name: 'Life',
        data: 1

    } , {
        name: 'Vehicles',
        data: 1

    }]

データ プロパティは配列でなければなりません。試す:

    series: [{
        name: 'Life',
        data: [<%=@jan_life[0].try(:total) %>] //note the brackets.

    } , {
        name: 'Vehicles',
        data: [<%=@feb_life[0].try(:total) %>]

    }]
于 2013-11-15T02:07:52.827 に答える