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
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"/>
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With