I need to开发者_运维百科 display some charts/graphs based upon user inputs on my web aplication built using Ruby on Rails. Are there any charting libraries out there that I could use with ROR for displaying simple bar, line and pie graphs?
There is a nice gem called
gruff
for graphs in ruby. You'll need the fabulous imagemagick and rmagick library. Since installation of the latter two is not really trivial (but not difficult, either), there's a installation FAQ for that.
Looks something like this:
More examples of this library: http://geoffreygrosenbach.com/projects/show/5
Down with flash and imagemagick.
Try Highcharts with the lazy high charts plugin for ruby: github.com/michelson/lazy_high_charts.
In addition to the aptly named googlecharts gem mentioned above there are two more that use the Google Charts API, gchartb and ruby-googlechart.
For the very awesome protovis javascript charting library, looks like someone has started a rails plugin called protovis on rails, but it still looks rough and hasn't been touched in a while.
Or cloudsource the charts via google - here's the gem for that: https://github.com/mattetti/googlecharts
Example:
# console
$ ruby script/plugin install git://github.com/mattetti/googlecharts.git
# view
<img src="<%=GoogleChart.pie(['1997',10],['1998',70],['1999',20]).to_url%>">
Open Flash Chart 2 is very nice and pretty easy. You get more dynamic features (tooltips, onclick, hover, ...): looks nice :)
In this related question a few more very interesting alternatives are mentioned. Of which i find the most interesting (i am not allowed to use hyperlinks -so use google :)
- flot, a jQuery based graphing library, with a rails plugin flotilla. Especially if you are already using jQuery in your Rails app, like i am.
- raphael, which looks very interesting, and also has a smaller brother gRaphael, especially for graphs/charts. A pure javascript, alas without any plugin for the moment. But that should not be too hard.
These are both javascript libraries, offering the same kind of visual appearance and interactive as the flash alternative, without the flash, which is imho a big advantage. Aside of which it even seems there are more interactive options/possibilities than the open flash chart can offer. I am going to check these out :)
I am not allowed to show more than 1 url, so Google is your friend :)
Hope this helps :)
There is another gem called scruffy that does not need rmagick & imagemagick/graphicsmagick if you want to generate only svg.
Here is the project page http://scruffy.rubyforge.org that has quite a few examples
For small graphs, there is Sparklines
Yui chart from Yahoo it works also offline. There is a ruby plugin for it, I didn't know the name of it, sorry.
Chartkick looks trending at the moment and also works with Highcharts.
I've two own options:
https://github.com/railsjazz/rails_charts - if you need to build complex charts, with many examples and helpers for easier use.
https://github.com/railsjazz/peity_vanilla_rails - if you need to add sparklines charts, simple, but informative (line, bar, pie..)
精彩评论