Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to draw a table #112

Closed
Shekharrajak opened this issue Jun 27, 2017 · 7 comments
Closed

How to draw a table #112

Shekharrajak opened this issue Jun 27, 2017 · 7 comments

Comments

@Shekharrajak
Copy link

I want to do something like this in my rails app : https://jsfiddle.net/wmqogfsu/

@Shekharrajak
Copy link
Author

Ping @winston , I see there is to_js method in data_table.rb but it is just generated the var data_table = ... for charts js code.

@winston
Copy link
Owner

winston commented Jun 28, 2017

Hi, please take a look at the examples in http://googlevisualr.herokuapp.com/. Thanks.

@winston winston closed this as completed Jun 28, 2017
@Shekharrajak
Copy link
Author

@winston , I saw that we can't draw table similar to charts using the gem. Since it is for only charts and for data table #to_js method is for only generating var data_table = new google.visualization.DataTable(.. not the js code inside the script tag .

Also render_chart is not for chart.

I edited some code and generated the script file.
few lines that I added :

   def to_js_web(element_id='random_id')
      js =  ""
      js << "\n<script type='text/javascript'>"
      js << load_js(element_id)
      js << draw_js(element_id)
      js << "\n</script>"
      js
    end

    def chart_function_name(element_id)
      "draw_#{element_id.gsub('-', '_')}"
    end

    def load_js(element_id)
      language_opt = ", language: '#{language}'" if language

      # "\n    google.charts.load('current', {packages: ['table']});"
      "\n  google.load('visualization', '#{version}', {packages: ['#{package_name}']#{language_opt}, callback: #{chart_function_name(element_id)}});"
    end


    def draw_js(element_id)
      js = ""
      js << "\n  function #{chart_function_name(element_id)}() {"
      js << "\n    #{self.to_js}"
      js << "\n    var table = new google.visualization.Table("
      js << "\n    document.getElementById('#{element_id}'));"
      js << "\n    table.draw(data_table, #{js_parameters(@options)});"
      js << "\n  };"
      js
    end

and added a new method render_table similarly for the chart. and It works.

@winston
Copy link
Owner

winston commented Jun 28, 2017

http://googlevisualr.herokuapp.com/docs

Hmm this page should show you how to generate tables. Does that work?

@Shekharrajak
Copy link
Author

Thanks for sharing this link. I didn't use GoogleVisualr::Interactive::Table.new(..)

but it is not working since it is taking packages: ['tabletable'] but package must be table.

@winston
Copy link
Owner

winston commented Jun 28, 2017

Hmm something wrong with the code then. But googlevisualr should be based on the latest version of the gem, so it should be correct.

@Shekharrajak
Copy link
Author

Yes, I am using the forked repo in rails app.

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

No branches or pull requests

2 participants