代码之家  ›  专栏  ›  技术社区  ›  Satchel

在Rails中使用Google Visualizer时,第一列和第二列必须是实体和时间,为什么?

  •  0
  • Satchel  · 技术社区  · 15 年前

    我正在使用一个Ruby包装器,它似乎适合使用Google可视化工具:

    https://github.com/jeremyolliver/gvis

    但是,我还是会遇到一个特别的错误:

    First and second columns must be entity and time 
    

    然而,据我所知,我传递的数据是实体和时间:

      <% chart_data = [
     ["Apples", Date.new(1998,1,1), 1000,300,'East'],
     ["Oranges", Date.new(1998,1,1), 950,200,'West'],
     ["Bananas", Date.new(1998,1,1), 300,250,'West'],
     ["Apples", Date.new(1998,2,1), 1200,400,'East'],
     ["Oranges", Date.new(1998,2,1), 950,150,'West'],
     ["Bananas", Date.new(1998,2,1), 788,617,'West']
     ] %>
    
    <% visualization "my_chart", "MotionChart", :width => 600, :height => 400, :html => {:class => "graph_chart"} do |chart| %>
    <%# Add the columns that the graph will have
    <% chart.string "Fruit" %>
    <% chart.date "Date" %>
    <% chart.number "Sales" %>
    <% chart.number "Expenses" %>
    <% chart.string "Location" %>
    
    <% chart.add_rows(chart_data) %>
    

    <%结束%>

    1 回复  |  直到 15 年前
        1
  •  0
  •   Sam å±±    15 年前

    本应配上海图的:)

    源代码的方式有点不同。

    add_rows 似乎是你在 chart_object 然后将数组作为方法传递

    <% chart.add_rows([
            ["Apples", Date.new(1998,1,1), 1000,300,'East'],
            ["Oranges", Date.new(1998,1,1), 950,200,'West'],
            ["Bananas", Date.new(1998,1,1), 300,250,'West'],
            ["Apples", Date.new(1998,2,1), 1200,400,'East'],
            ["Oranges", Date.new(1998,2,1), 950,150,'West'],
            ["Bananas", Date.new(1998,2,1), 788,617,'West']
        ]) %>
    

    所以这个插件创建了一个 chart 添加行 方法传递数组。

    <% chart.add_rows([this is where you pass your arrays]) %>