0

New to Rails. How can I export data from my database( I'm using Sqlite3) into a chart in rails? I have 2 columns I would like to visualizes, Timestamps and Decimal values.

I have seen plenty of examples on how to display data with Google Charts in rails, but never data from a db.

Any instruction or examples would be appreciated.

4

2 回答 2

1

编写一个将返回 json 数据的 web 服务,用它来填充图表看这里http://pivotallabs.com/building-a-fast-lightweight-rest-service-with-rails-3/

于 2013-06-11T20:25:59.940 回答
1

Well, I guest you are using googlecharts gem. In the page there are a lot of really basic examples. like this one:

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

So, instead of put the numbers, yo can put your data like this

Gchart.line(:data => MyModel.pluck(:my_attribute))

where my_atributte is a column in the MyModel Object

this will create a link like this: http://chart.apis.google.com/chart?chd=s:AjI9R&cht=lc&chs=300x200&chxr=0,0,70

and you can use it as you want... maybe put in a img tag or whatever

于 2013-06-11T20:52:25.770 回答