mattetti/googlecharts

can't convert fixnum to array

Closed this issue · 3 comments

Hi Matt:

I'm trying to generate a stacked bar chart using googlecharts. I pass a 2-d array containing nils and bignums to Gchart.bar and get a "can't convert Fixnum into Array" error. Any suggestions?

Thanks,

Dean Richardson

Here's the error text:

TypeError in Users#timesheets

Showing app/views/users/timesheets.html.erb where line #53 raised:

can't convert Fixnum into Array

Extracted source (around line #53):

50: <% @bar_data[@date_index] = @project_hours %>
51: <% end %>
52: <% puts @bar_data %>
53: <%= image_tag Gchart.bar(:data => @bar_data, :size => '400,300') %>
54:
55:
56:

RAILS_ROOT: /Users/Lowell/rails_projects/molex_app
Application Trace | Framework Trace | Full Trace

/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:586:in -' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:586:inencode_scaled_dataset'
/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:581:in map' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:581:inencode_scaled_dataset'
/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:580:in each' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:580:inencode_scaled_dataset'
/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:570:in each' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:570:inencode_scaled_dataset'
/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:602:in simple_encoding' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:321:insend'
/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:321:in set_data' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:637:inquery_builder'
/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:634:in map' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:634:inquery_builder'
/Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:630:in url_builder' /Library/Ruby/Gems/1.8/gems/googlecharts-1.6.0/lib/gchart.rb:292:inurl'
(eval):12:in send' (eval):12:inbar'
/Users/Lowell/rails_projects/molex_app/app/views/users/timesheets.html.erb:53:in _run_erb_app47views47users47timesheets46html46erb' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:34:insend'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:34:in render' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:306:inwith_template'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/renderable.rb:30:in render' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/template.rb:205:inrender_template'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:265:in render' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:348:in_render_with_layout'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_view/base.rb:262:in render' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1250:inrender_for_file'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:945:in render_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:51:inrender'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:51:in render' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1326:indefault_render'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:1332:in perform_action_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:617:incall_filters'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:610:in perform_action_without_benchmark' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:inperform_action_without_rescue'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/benchmarking.rb:68:in perform_action_without_rescue' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/rescue.rb:160:inperform_action_without_flash'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/flash.rb:146:in perform_action' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:insend'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:532:in process_without_filters' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/filters.rb:606:inprocess'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:391:in process' /Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:386:incall'
/Library/Ruby/Gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:437:in `call'

Could you please show me how @bar_data look like? It looks from the error message that the API is expecting another object type.

Matt:

I tried changing the column in my database from decimal (BigNum) to float. The error message persisted. [I rebooted my local server, just to be sure, same problem.]

My array contained nil values, so I figured that might be the real issue. I added code to initialize the array to the right size with zeros for every element. This time the error went away.

So it's working great now. I'm using pretty much all the options you show in your examples: text encoding, maxval, legends, axes, axis labels, I'm quite pleased with the results thus far.

Thanks!

Dean

Glad to hear that!