Help Using Flotilla and Ruby on Rails

I'm new to Rails (and StackOverflow), so I apologize if this is a "dumb" question. I put together a very simple Rails application. It receives data from another server (via HTTP POST). I would like to calculate the data sent - in particular, I am looking for a graph of temperature versus time.

I am trying to use Flotilla to create these graphs, but I cannot find much documentation on how to use this except for the one-line example on the main page:

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

This is my 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 />

The first part simply prints a list of temperatures and times. It works great. Unfortunately, the second part - the actual schedule - does not seem to work. Nothing is actually displayed.

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>

. .

+3
2

, :

<%= javascript_include_tag 'jquery-1.5.1','flot/jquery.flot.js','excanvas.pack.js','jquery.flot.pack.js' %>

javascripts, . , js /public/javascripts/folder

+6

div id graph ; .

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

id , , chart.

, Flot.

+5

Source: https://habr.com/ru/post/1703653/


All Articles