帮助使用Flotilla和Ruby on Rails

3 graphing ruby-on-rails flot

我是Rails(和StackOverflow)的新手,所以如果这是一个"愚蠢"的问题我很抱歉.我已经整理了一个非常简单的Rails应用程序.它从另一台服务器接收数据(通过HTTP POST).我想绘制发送的数据 - 特别是,我希望图表温度与时间.

我试图使用Flotilla生成这些图形,但我似乎找不到关于如何使用它的文档,除了主页上的一行示例:

        = chart("graph", {"Store 1" => {:collection => @store_one, :x => :date, :y => :sales }, "Store 2" => {:collection => @store_two, :x => :date, :y => :sales }})
Run Code Online (Sandbox Code Playgroud)

这是我的index.html.erb:

<table>
  <tr>
    <th>Temperature</th>
    <th>Time</th>
  </tr>

<% for post in @posts %>
  <tr>
    <td><%=h post.temperature %></td>
    <td><%=h post.created_at %></td>
  </tr>
<% end %>
</table>
<%= chart("graph", { "Graph1" => { :collection => @posts, :x => :created_at, :y => :temperature }})%>
<br />
Run Code Online (Sandbox Code Playgroud)

第一部分只是打印出温度和时间列表.这很好用.不幸的是,第二部分 - 实际图表 - 似乎不起作用.什么都没有显示.

如果我查看生成的HTML的来源,我看到:

    <script language="javascript" type="text/javascript" src="/javascripts/jquery.flot.pack.js"></script>
    <script type="text/javascript">
      $.plot($('#graph'), [{"data":[[1234191865.0,12.0],[1234192069.0,15.0],[1234192113.0,16.0],[1234192123.0,18.0],[1234192189.0,21.0],[1234192203.0,25.0],[1234192320.0,27.0],[1234192329.0,29.0],[1234192384.0,30.0],[1234192391.0,31.0],[1234192402.0,35.0],[1234192409.0,29.0],[1234192412.0,31.0],[1234192414.0,27.0],[1234192419.0,25.0],[1234211826.0,27.0]],"label":"Graph1"}], {});
    </script>
Run Code Online (Sandbox Code Playgroud)

但是没有显示实际的图表.在此先感谢您的帮助.

小智 6

对我有用的是在视图的顶部添加这一行:

<%= javascript_include_tag 'jquery-1.5.1','flot/jquery.flot.js','excanvas.pack.js','jquery.flot.pack.js' %>
Run Code Online (Sandbox Code Playgroud)

这意味着在我的视图中包含为了使用flot所需的所有javascripts.还要确保在/ public/javascripts /文件夹下包含所有js文件


vla*_*adr 5

尝试在页面的任何位置添加div带ID 的元素graph; 它将用作图表的画布.

<div id="graph" style="width:600px;height:300px;"></div>

id元素必须传递的第一个参数匹配的字符串chart.

如有疑问,您可以查看Flot站点上各种示例页面的来源.