开发者

I get an First and second columns must be entity and time when using Google Visualizer in Rails, why?

I am using a Ruby wrapper which appears to be correct for using Google Visualizer:

https://github.com/jeremyolliver/gvis

However, I keep getting this particular error:

First and second columns must be entity and time 

However, the data I am passing are entity and time as far as I understand:

  <% 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| %>开发者_JAVA百科
<%# 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) %>

<% end %>

I'm not sure how to debug because I'm not getting enough information to work with in the errors....


Should have gone with highcharts :)

The way the source code has it is a little different.

add_rows seems to be the method you call on the chart_object and then you pass your array of arrays as a method

<% 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']
    ]) %>

so this plugin creates a chart object with the add_rows method for you to pass in your arrays.

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜