I am trying to use the googlecharts (http://googlecharts.rubyforge.org/) gem. Where do you put the code to generate a chart (like Gchart.line(:data => [0, 40, 10, 70, 20]) )? How do you display it?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Calling
Gchart.line()simply returns a string that is the URL for the corresponding Google Chart image. E.g.Gchart.line(:data => [0, 40, 10, 70, 20])returns"http://chart.apis.google.com/chart?chd=s:AjI9R&cht=lc&chs=300x200&chxr=0,0,70".So, to display a chart on your page, you will need to create an image tag with a source of this generated URL. You can call Gchart directly from the view or set up the variable in your controller.
For example:
Controller
@line_chart = Gchart.line(:data => [0, 40, 10, 70, 20])View
<%= image_tag(@line_chart) %>This will generate an image tag like so:
<img src="http://chart.apis.google.com/chart?chd=s:AjI9R&cht=lc&chs=300x200&chxr=0,0,70"/>.