How to use gorge garts?

I am trying to use gorge googlecharts (http://googlecharts.rubyforge.org/). Where do you put the code to create the chart (for example Gchart.line(:data => [0, 40, 10, 70, 20]) )? How do you show it?

thank

+3
source share
2 answers

The call Gchart.line()simply returns a string, which is the URL of the corresponding Google Chart image. For instance. 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, in order to display a diagram on your page, you need to create an image tag with the source of this generated URL. You can call Gchart directly from the view or configure a variable in your controller.

For instance:

Controller @line_chart = Gchart.line(:data => [0, 40, 10, 70, 20])

View <%= image_tag(@line_chart) %>

: <img src="http://chart.apis.google.com/chart?chd=s:AjI9R&cht=lc&chs=300x200&chxr=0,0,70"/>.

+12

, , . - :

<%= Gchart.line(:data => [0, 40, 10, 70, 20]) %>

html, .

+1

All Articles