Ruby on Rails 上的 Gem Seer 和 Ajax
我正在尝试使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在进行ajax调用时,您需要手动绘制图表。
Seer 用户使用“drawChart()”方法来绘制图表。
下面是我的 ajax 响应
不要忘记评估您的 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
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.
有几个问题......如果你移动 <%= 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.