2013-11-26 29 views
0

我正在嘗試使用gruff寶石創建一個餅圖,但無論我做什麼,我的圖表都是黑色深淵。這是我的代碼:在Ruby中生成粗糙的寶石餅圖

association_disposition_pie_chart = Gruff::Pie.new 
association_disposition_pie_chart.title = "Visual Pie Graph Test" 
association_disposition_pie_chart.data 'Solved', 10 
association_disposition_pie_chart.data 'Action Required', 50 
    association_disposition_pie_chart.theme = { 
     :colors => ['#A5D8D8', '#EFAD1C'], 
     :font_color => 'black', 
     :background_colors => 'white' 
    } 
association_disposition_pie_chart.write("association_disposition_pie_chart.jpg") 

爲什麼創建黑色餅圖?背景是白色的,font_color是黑色的,但整個圖表也是如此。我希望圖表部分是:colors中指定的顏色。

EDIT

截圖:

http://i39.tinypic.com/33ne1r6.jpg

+0

也許這會有所幫助。看起來像你幾乎寫在那裏的CSS:http://gruff.rubyforge.org/classes/Gruff/Base.html#M000047 –

回答

0

此文檔中被提及:

You can set a theme manually. Assign a hash to this method before you send your data. 

graph.theme = { 
    :colors => %w(orange purple green white red), 
    :marker_color => 'blue', 
    :background_colors => %w(black grey) 
} 
:background_image => 'squirrel.png' is also possible. 

(Or hopefully something better looking than that.) 

雖然源是更有幫助的:

# File 'lib/gruff/base.rb', line 300 

def theme=(options) 
    reset_themes() 

    defaults = { 
    :colors => ['black', 'white'], 
    :additional_line_colors => [], 
    :marker_color => 'white', 
    :font_color => 'black', 
    :background_colors => nil, 
    :background_image => nil 
    } 
    @theme_options = defaults.merge options 

    @colors = @theme_options[:colors] 
    @marker_color = @theme_options[:marker_color] 
    @font_color = @theme_options[:font_color] || @marker_color 
    @additional_line_colors = @theme_options[:additional_line_colors] 

    render_background 
end 

我認爲也許問題是你的colors屬性 - :colors => ['#A5D8D8', '#EFAD1C'] - 如Shaun Frost Duke Jackson提到,它看起來像你需要使用add_color('#c0e9d3')來做到這一點,但文檔不清楚你在哪裏做的,如果你定義的主題行。這可能是更容易添加自己的主題,在THEMES module

LUIGIS_THEME = { 
     :colors => [ 
     '#A5D8D8', 
     '#EFAD1C' 
     ], 
     :marker_color => '#55ae36', 
     :font_color => 'black', 
     :background_colors => 'white' 
    } 

然後用g.theme = Gruff::Themes::LUIGIS_THEME

+0

這是有道理的,並感謝提示。我繼續設置,但我仍然遇到同樣的問題。數據「標籤」以正確的顏色顯示,但實際的餅圖仍然全黑。當我切換到默認的PASTEL主題時,數據標籤再次以柔和的顏色顯示,但餅圖是半白/半黑。有關圖表爲什麼沒有反映數據標籤顏色的任何想法? – Luigi

+0

你可以添加一個屏幕截圖到你的文章,也許?你有沒有嘗試過各種屬性?也許設置':background_colors =>%w(#d1edf5 white)'看看會發生什麼? – dax

+0

我試過了,還有一些其他選項,仍然醒目。我附上了我最近一次嘗試的截圖。我嘗試傳遞一些更多參數的粉彩主題,並創建半白/半黑圖。只有2個數據點,它仍然是全黑的。 – Luigi

0

稱爲雖然使用ImageMagick-NO-HDRI和默認rmagick寶石餅圖會變成黑色和白色。我能夠通過執行以下操作來解決此問題

Install imagemagick 
git clone [email protected]:rmagick/rmagick.git 
gem build rmagick.gemspec 
gem install ./rmagick-2.13.2.gem 
+0

我將很快測試 - 感謝您的提示。 – Luigi