我正在尝试使用gruff
宝石创建一个饼图,但无论我做什么,我的图表都是黑色的深渊。这是我的代码:
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
中指定的颜色。
截图:
答案 0 :(得分: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
调用
答案 1 :(得分:0)
使用imagemagick-no-hdri和默认的rmagick gem时,饼图会变成黑白色。我通过执行以下操作来解决此问题
Install imagemagick
git clone git@github.com:rmagick/rmagick.git
gem build rmagick.gemspec
gem install ./rmagick-2.13.2.gem