Don’t Worry.Be Scruffy.

简介:

Scruffy是什么?

Scruffy是一个用来生成图表的ruby库,它的功能非常强大,可以用它来做web开发,在页面上输出多媒体数据。
 
Scruffy的主要特性包括:
  • 基于 SVG
    Scruffy 基于 SVG 技术来生成图表 . 这也使得Scruffy具备SVG的许多优点,譬如文件的大小与图形的复杂程度有关,而与图形的具体尺寸无关。
  • Mix-n-Match Graphs
    对于Scruffy生成的图表不局限于单一的图表类型(线,柱状,区域等)。你可以对每一个数据集指定一个不同的类型
  • 快照呈递
    你可以任意的多次输出同一个Scruffy图表,或者是修改每一次输出图表的设置(数据、颜色,甚至图表的尺寸和图标类型)。
  • 可扩展性
    Scruffy具有很强的可扩展性。可以通过仅仅几行代码来添加新的图表类型或者主题。  如果你需要更多的图像控制功能,也可以自定义输出,生成数据等等内容。
安装
sudo gem install scruffy

实例:

饼图

    
    
graph = Scruffy::Graph.new graph.title = "Favourite Snacks" graph.renderer = Scruffy::Renderers::Pie.new graph.add :pie, '', { 'Apple' => 20, 'Banana' => 100, 'Orange' => 70, 'Taco' => 30 } graph.render :to => "pie_test.svg" graph.render :width => 300, :height => 200, :to => "pie_test.png", :as => 'png'

直线图:

    
    
graph = Scruffy::Graph.new graph.title = "Sample Line Graph" graph.renderer = Scruffy::Renderers::Standard.new graph.add :line, 'Example', [20, 100, 70, 30, 106] graph.render :to => "line_test.svg" graph.render :width => 300, :height => 200, :to => "line_test.png", :as => 'png'

柱状图

    
    
graph = Scruffy::Graph.new graph.title = "Sample Line Graph" graph.renderer = Scruffy::Renderers::Standard.new graph.add :line, 'Example', [20, 100, 70, 30, 106] graph.render :to => "line_test.svg" graph.render :width => 300, :height => 200, :to => "line_test.png", :as => 'png'

分离图

    
    
graph = Scruffy::Graph.new graph.title = "Long-term Comparisons" graph.value_formatter = Scruffy::Formatters::Currency.new( :special_negatives => true, :negative_color => '#ff7777') graph.renderer = Scruffy::Renderers::Split.new( :split_label => 'Northeastern (Top) / Central (Bottom)') graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106, 203, 100, 50, 203, 289, 20], :category => :top graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26, 30, 106, 203, 100, 50, 39], :category => :top graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203, 70, 20, 102, 201, 26, 130], :category => :bottom graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70, -10, -20, 50, 92, -21, 19], :categories => [:top, :bottom] graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56, 92, 84, 82, 100, 39, 120], :categories => [:top, :bottom] graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] graph.render :to => "split_test.svg" graph.render :width => 500, :to => "split_test.png", :as => 'png'

堆叠图
   
graph = Scruffy::Graph.new
    graph.title = "Comparative Agent Performance"
    graph.value_formatter = Scruffy::Formatters::Percentage.new(:precision => 0)
    graph.add :stacked do |stacked|
      stacked.add :bar, 'Jack', [30, 60, 49, 29, 100, 120]
      stacked.add :bar, 'Jill', [120, 240, 0, 100, 140, 20]
      stacked.add :bar, 'Hill', [10, 10, 90, 20, 40, 10]
    end
    graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
    graph.render :to => "stacking_test.svg"
    graph.render  :width => 500, :to => "stacking_test.png", :as => 'png'

层叠

    
    
graph = Scruffy::Graph.new graph.title = "Some Kind of Information" graph.renderer = Scruffy::Renderers::Cubed.new graph.add :area, 'Jeff', [20, -5, 100, 70, 30, 106], :categories => [:top_left, :bottom_right] graph.add :area, 'Jerry', [-10, 70, 20, 102, 201, 26], :categories => [:bottom_left, :buttom_right] graph.add :bar, 'Jack', [30, 0, 49, 29, 100, 203], :categories => [:bottom_left, :top_right] graph.add :line, 'Brasten', [42, 10, 75, 150, 130, 70], :categories => [:top_right, :bottom_left] graph.add :line, 'Jim', [-10, -20, 50, 92, -21, 56], :categories => [:top_left, :bottom_right] graph.point_markers = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'] graph.render :to => "multi_test.svg" graph.render :width => 500, :to => "multi_test.png", :as => 'png'





本文转自 fsjoy1983 51CTO博客,原文链接:http://blog.51cto.com/fsjoy/168842,如需转载请自行联系原作者
目录
相关文章
|
3月前
|
安全
Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yo
Warning: Don’t paste code into the DevTools Console that you don’t understand or haven’t reviewed yo
|
5月前
|
SQL 关系型数据库 MySQL
Unknown column ‘xx’ in ‘on clause’
Unknown column ‘xx’ in ‘on clause’
39 0
|
Java Go API
译|Don’t just check errors, handle them gracefully(二)
译|Don’t just check errors, handle them gracefully(二)
92 0
|
程序员 Go API
译|Don’t just check errors, handle them gracefully(一)
译|Don’t just check errors, handle them gracefully
78 0
|
算法 Linux 测试技术
【论文阅读】(2014)Combinatorial Benders’ Cuts for the Strip Packing Problem
【论文阅读】(2014)Combinatorial Benders’ Cuts for the Strip Packing Problem
242 0
【论文阅读】(2014)Combinatorial Benders’ Cuts for the Strip Packing Problem
|
自然语言处理
Re26:读论文 Don’t Stop Pretraining: Adapt Language Models to Domains and Tasks
Re26:读论文 Don’t Stop Pretraining: Adapt Language Models to Domains and Tasks
Re26:读论文 Don’t Stop Pretraining: Adapt Language Models to Domains and Tasks
Don't give me five!
Don't give me five!
90 0
|
C++
201312-5 I’m stuck!
201312-5 I’m stuck!
80 0
201312-5 I’m stuck!
|
数据库
When Tech Meets Love – Smarter Ways to NOT be Single
It’s that time of year again. Single’s Day (a.k.a Double 11) is just around the corner, people buying gifts for loved ones.
1623 0
When Tech Meets Love – Smarter Ways to NOT be Single
|
Perl
The document could not be saved. The file doesn’t exist.
有时候莫名其妙的pod update之后(可能是拖拽文件到pod子项目导致的,具体忘了,出现问题的时候已经忘了之前干啥了。。。囧~),然后某一个或者几个文件就不能编辑保存了,编译不过,如下: The document could not be autosaved.
2815 0