Skip to content
This repository has been archived by the owner on Jan 2, 2018. It is now read-only.

Bar chart doesn't seem to cope gracefully with empty dataset #72

Open
mockdeep opened this issue Oct 13, 2014 · 6 comments
Open

Bar chart doesn't seem to cope gracefully with empty dataset #72

mockdeep opened this issue Oct 13, 2014 · 6 comments

Comments

@mockdeep
Copy link

When I have an empty data set, I get an error from google charts:

 > Gchart.bar(:data => [[],[],[]])
NoMethodError: undefined method `-' for nil:NilClass
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:594:in `block in encode_scaled_dataset'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:592:in `each'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:592:in `encode_scaled_dataset'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:624:in `simple_encoding'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:328:in `set_data'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:659:in `block in query_builder'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:656:in `map'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:656:in `query_builder'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:652:in `url_builder'
    from /home/fletch/.rvm/gems/ruby-2.1.2/gems/googlecharts-1.6.8/lib/gchart.rb:299:in `url'
    from (eval):12:in `bar'
    from (irb):3
@kathgironpe
Copy link
Collaborator

@mockdeep shouldn't you be checking if data set is empty before using Gchart?

@mockdeep
Copy link
Author

@katgironpe It doesn't seem like the role of the library to make that decision for users. If I pass an empty data set to the Google Charts API, it returns a blank graph, which is fine for my purposes. At the very least, a meaningful error message would be helpful.

@Chuongv
Copy link

Chuongv commented Oct 14, 2014

So your expectation is that it returns an empty graph? Or an error?

@kathgironpe
Copy link
Collaborator

@mockdeep it's a rare case but agree about proper error handling.

@mockdeep
Copy link
Author

I think the ideal situation for me would be for it just to return an empty graph. It's fairly common in the dev environment and in tests to have empty graphs, so it would be nice just to render it transparently instead of having to handle the error case.

@Seven0711
Copy link

请问使用Google chart要引入哪些文件,去哪里下载?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants