Ruby on Rails 上的 Gem Seer 和 Ajax

发布于 2024-11-03 16:52:49 字数 1334 浏览 3 评论 0原文

我正在尝试使用 Ajax 使用 Seer 显示折线图。

但当我发出 ajax 请求时,我得到的只是一个空白页面。当我使用 render :partial 显示时,相同的部分工作正常。

这是部分 _show.html.erb

<div id="chart"></div>
<%= Seer::init_visualization -%>
<%= Seer::visualize(
      sensors, 
      :as => :line_chart,
      :in_element => 'chart',
      :series => {
        :series_label => 'location',
        :data_label => 'id',
        :data_method => 'value',
        :data_series => series
      },
      :chart_options => { 
        :height => 250,
        :width => 500,
        :axis_font_size => 12,
        :colors => ['#0099CC','#990000','#009900'],
        :title => "Rain Data",
        :point_size => 0,
        :line_size => 3,
        :title_y => "Water Level in Feet",
        :smooth_line => "true",
      }
     )
 -%>

这有效:

<%= render :partial => 'hcfcdsensors/show', :locals => {:sensors => @sensors , :series => @series} %>

但这无效:

<%= link_to_remote "show" , :url => show_graph_hcfcd_url(@hcfcdsensors) ,:update => "graphDiv" %>

整个网页变成空白。 我已经检查了页面中所需变量的操作和可用性,一切都很好。

欢迎任何帮助。

谢谢 肖纳克

I am trying to display a Line graph using Seer using Ajax.

But all I get is a blank page when I make an ajax request.The same partial works fine when I display is using a render :partial.

Here is the partial _show.html.erb

<div id="chart"></div>
<%= Seer::init_visualization -%>
<%= Seer::visualize(
      sensors, 
      :as => :line_chart,
      :in_element => 'chart',
      :series => {
        :series_label => 'location',
        :data_label => 'id',
        :data_method => 'value',
        :data_series => series
      },
      :chart_options => { 
        :height => 250,
        :width => 500,
        :axis_font_size => 12,
        :colors => ['#0099CC','#990000','#009900'],
        :title => "Rain Data",
        :point_size => 0,
        :line_size => 3,
        :title_y => "Water Level in Feet",
        :smooth_line => "true",
      }
     )
 -%>

This works:

<%= render :partial => 'hcfcdsensors/show', :locals => {:sensors => @sensors , :series => @series} %>

But this Doesn't:

<%= link_to_remote "show" , :url => show_graph_hcfcd_url(@hcfcdsensors) ,:update => "graphDiv" %>

The complete web page just goes blank.
I have checked the action and availability of required variables in the page and its all there fine.

Any help is welcome.

Thanks
Shaunak

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

久光 2024-11-10 16:52:49

在进行ajax调用时,您需要手动绘制图表。
Seer 用户使用“drawChart()”方法来绘制图表。

下面是我的 ajax 响应

<% result_script = Seer::visualize(
      @flight_result_search.sell_classes_for_graph, 
      :as => :area_chart,
      :in_element => 'historical_sellout_chart',
      :series => {
        :series_label => 'name',
        :data_label => 'days_prior',
        :data_method => 'capacity',
        :data_series => [@flight_result_search.current_sell_for_graph,@flight_result_search.historical_sell_for_graph]
      },
      :chart_options => { 
        :height => 400,
        :width => 600,
        :axis_font_size => 11,
        :title => "Historical Sell Out Chart",
        :point_size => 3,
        :color =>['#324F69','#90000B']
      }
     )

%>
<%= result_script.gsub("</script>",' drawChart();</script>') %>

不要忘记评估您的 ajax 响应,因为它是 javascript 代码。
另外,drawChart() 应该位于相同的脚本标记中,否则它不起作用。

When making ajax call, You need to draw the chart manually.
Seer user " drawChart()" method to draw the chart.

Below is my ajax response

<% result_script = Seer::visualize(
      @flight_result_search.sell_classes_for_graph, 
      :as => :area_chart,
      :in_element => 'historical_sellout_chart',
      :series => {
        :series_label => 'name',
        :data_label => 'days_prior',
        :data_method => 'capacity',
        :data_series => [@flight_result_search.current_sell_for_graph,@flight_result_search.historical_sell_for_graph]
      },
      :chart_options => { 
        :height => 400,
        :width => 600,
        :axis_font_size => 11,
        :title => "Historical Sell Out Chart",
        :point_size => 3,
        :color =>['#324F69','#90000B']
      }
     )

%>
<%= result_script.gsub("</script>",' drawChart();</script>') %>

Don't forget to eval your ajax response as it is javascript code .
Also drawChart() should be in same script tag otherwise it doesn't work.

坚持沉默 2024-11-10 16:52:49

有几个问题......如果你移动 <%= Seer::init_visualization -%> 会发生什么?到封闭页面而不是部分页面?另外,刷新页面时检查是否存在任何 JavaScript 错误。在 Safari 或 Firefox 中,打开控制台进行检查。

Couple of questions... what happens if you move <%= Seer::init_visualization -%> to the enclosing page rather than the partial? Also, check to see if there are any JavaScript errors when you refresh the page. In Safari or Firefox, open up the Console to check.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文