0

我有这个 JS highchart,我试图将一些值传递给在我的pages_controller. 我已经尝试过使用全局变量和实例变量,但似乎都不适用于渲染。我猜这个值没有传入。

在我的pages_controller我有:

> @nil_ref = (@counts[nil]/total.to_f)*10
> @email_ref = (@counts["email"]/total.to_f)*10
> @cpc_ref = (@counts["cpc"]/total.to_f)*10
> @display_ref = (@counts["display"]/total.to_f)*10

然后在我的 /public/highcharts.js 文件中,我有:

var chart1; // globally available
   $(document).ready(function () {
       var chart = new Highcharts.Chart({
           chart: {
               renderTo: 'container',
               type: 'pie'
           },
           xAxis: {
               categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
           },
           yAxis: {   
           },
           legend: {
               layout: 'vertical',
               floating: true,
               backgroundColor: '#eeeeee',
               align: 'right',
               verticalAlign: 'top',
               y: 60,
               x: -60
           },
           tooltip: {
               formatter: function() {
                   return '<b>'+ this.series.name +'</b><br/>'+
                       this.x +': '+ this.y;
               }
           },
           plotOptions: {
           },
           series: [{
               data: [<%= @nil_ref %>, <%= @email_ref %>, <%= @cpc_ref %>, <%= @display_ref %>] //These need to be global vars        
           }]
       });
   });

当我在 Chrome 中检查元素时,我得到Uncaught SyntaxError: Unexpected token了 JS 中的 Ruby 标签。

任何想法如何成功传递这些值?

4

1 回答 1

1

如果 RoR 数据是字符串,您需要这样做:

data: ["<%= @nil_ref %>", "<%= @email_ref %>", ...
于 2012-06-26T17:14:50.183 回答