在 Ruby on Rails Web 应用程序中生成图表的首选方法是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/87561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 20:39:53  来源:igfitidea点击:

What is your preferred way to produce charts in a Ruby on Rails web application?

ruby-on-railsrubycharts

提问by RichH

I'd like to add some pie, bar and scatter charts to my Ruby on Rails web application. I want want them to be atractive, easy to add and not introduce much overhead.

我想向我的 Ruby on Rails Web 应用程序添加一些饼图、条形图和散点图。我希望它们具有吸引力,易于添加并且不会引入太多开销。

What charting solution would you recommend?
What are its drawbacks (requires Javascript, Flash, expensive, etc)?

您会推荐什么图表解决方案?
它的缺点是什么(需要 Javascript、Flash、昂贵等)?

采纳答案by Clinton N. Dreisbach

Google Chartsis an excellent choice if you don't want to use Flash. It's pretty easy to use on its own, but for Rails, it's even easier with the gchartrbgem. An example:

如果您不想使用 Flash,Google Charts是一个不错的选择。它本身很容易使用,但对于 Rails,使用gchartrbgem更容易。一个例子:

GoogleChart::PieChart.new('320x200', "Things I Like To Eat", false) do |pc| 
  pc.data "Broccoli", 30
  pc.data "Pizza", 20
  pc.data "PB&J", 40 
  pc.data "Turnips", 10 
  puts pc.to_url 
end

回答by Ben Crouse

If you don't need images, and can settle on requiring JavaScript, you could try a client-side solution like the jQuery plugin flot.

如果您不需要图像,并且可以满足于需要 JavaScript,则可以尝试使用客户端解决方案,例如 jQuery 插件flot

回答by lordscarlet

I am a fan of Gruff Graphs, but Google Chartsis also good if you don't mind relying on an external server.

我是Gruff Graphs的粉丝,但如果您不介意依赖外部服务器,Google Charts也不错。

回答by Otto

It requires flash andisn't free (though inexpensive): amcharts.

需要闪存并且不是免费的(虽然便宜):amcharts

I've used it successfully and like it. I evaluated a number of options a while back and chose it. At the time, however, Google Charts wasn't as mature as it seems to be now. I would consider that first if I were to re-evaluate now.

我已经成功地使用它并喜欢它。不久前我评估了许多选项并选择了它。然而,当时的 Google Charts 并不像现在看起来那么成熟。如果我现在重新评估,我会首先考虑这一点。

回答by Matthias Winkelmann

There's also Scruffy. I took a look at the code recently and it seemed easy to modify/extend. It produces svg and (by conversion) png.

还有邋遢。我最近查看了代码,似乎很容易修改/扩展。它生成 svg 和(通过转换)png。

回答by David Heggie

Have you tried the Google Charts API? - web service APIs don't really come much simpler. It's free to use, simple to implement, and the charts don't look too shoddy.

您是否尝试过Google Charts API?- Web 服务 API 并没有变得更简单。它可以免费使用,易于实现,而且图表看起来不会太粗劣。

回答by Clinton N. Dreisbach

Open Flash Chart IIis a free option that gives very nice output. It does, as you'd expect, require Flash.

Open Flash Chart II是一个免费选项,可以提供非常好的输出。正如您所期望的那样,它确实需要 Flash。

Fusion Chartsis even nicer, but is $499. In researching this, I found a cut-down free versionthat might serve your needs.

Fusion Charts更好,但售价 499 美元。在研究这一点时,我发现了一个可以满足您需求的精简免费版本

回答by Jerry Cheung

I 2nd the vote for flot. The latest version lets you do some animations and actions that I previously thought would only be possible via Flash. The documentation is fantastic. It simple to write by hand, but for simple cases it gets even easier with a Rails plugin called flotilla. You should check out the examples pagefor a better idea of what it's capable of. The zooming and hover capabilities are especially impressive.

我 2nd 投票给flot。最新版本允许您执行一些我以前认为只能通过 Flash 实现的动画和动作。文档很棒。手工编写很简单,但对于简单的情况,使用名为flotilla的 Rails 插件会更容易。您应该查看示例页面以更好地了解它的功能。缩放和悬停功能尤其令人印象深刻。

回答by RichH

The new Google Visualization appears to produce charts that are of more varied type, better looking and interactive than Google Graphs.

与 Google Graphs 相比,新的 Google Visualization 似乎可以生成类型更多样化、外观更好、交互性更好的图表。

http://code.google.com/apis/visualization/

http://code.google.com/apis/visualization/

回答by Steven Yue

Morris.jsis nice and open source. I would like to choose it comparing to highcharts. There is a new great video tutorial from Railscasts

Morris.js很好,而且是开源的。与highcharts相比,我想选择它。Railscasts有一个很棒的新视频教程