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

发布于 2024-09-30 14:17:29 字数 1114 浏览 4 评论 0原文

我正在使用 Ruby 包装器,它似乎适合使用 Google Visualizer:

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

<% end %>

我不知道如何调试,因为我没有获得足够的信息来处理错误......

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| %>
<%# 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....

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

淡忘如思 2024-10-07 14:17:29

应该使用 highcharts :)

源代码的方式有点不同。

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 对象使用 add_rows 方法传递数组。

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

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]) %>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文