0

I am attempting to create a pie chart using the gruff gem, but my chart is a black abyss regardless of what I do. This is my code:

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")

Why is this creating a black pie chart? The background is white, the font_color is black, but so is the entire chart. I want the chart pieces to be the colors specified in :colors.

EDIT

Screenshot:

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

Community
  • 1
  • 1
Luigi
  • 5,443
  • 15
  • 54
  • 108

2 Answers2

0

This is mentioned in the documentation:

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.)

Although the source is more helpful:

# 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

I think maybe the problem is your colors attribute - :colors => ['#A5D8D8', '#EFAD1C'] - as Shaun Frost Duke Jackson mentioned, it looks like you need to use add_color('#c0e9d3') to do that, but the documentation isn't clear where you do that if you're defining the theme in line. It might be easier to add your own theme in the THEMES module:

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

which is then called with g.theme = Gruff::Themes::LUIGIS_THEME

Community
  • 1
  • 1
dax
  • 10,779
  • 8
  • 51
  • 86
  • This makes sense, and thanks for the tip. I went ahead and set that up, but I'm still running into the same issue. The data "labels" are showing up in the right colors, but the actual pie chart is still all black. When I switch to the default PASTEL theme the data labels again show up in pastel colors, but the pie chart is half white/half black. Any thoughts on why the chart isn't reflecting the data label colors? – Luigi Nov 27 '13 at 13:44
  • could you add a screen shot to your post, perhaps? have you tried playing around with the various attributes? maybe set `:background_colors => %w(#d1edf5 white)` and see what happens? – dax Nov 27 '13 at 13:50
  • I've tried that and a few other options, still striking out. I attached a screenshot of my most recent try. I tried passing in the Pastel theme with a few more parameters, and that creates the half white/half black chart. With only 2 data points it's still all black. – Luigi Nov 27 '13 at 14:01
  • what about adding more colors to the `colors` array? – dax Nov 27 '13 at 14:03
  • No dice. I've created no less than 100 different charts and graphs with the Gruff tool, not sure why I'm having such an issue with this pie chart... – Luigi Nov 27 '13 at 14:04
  • huh...really strange. i can't see any other possible problem, but actually i think i've used Gruff less than you. maybe make a [new issue](https://github.com/topfunky/gruff/issues)? – dax Nov 27 '13 at 14:08
  • Sure thing. Thanks for the help, I appreciate it. I'll post back here if I find an answer. – Luigi Nov 27 '13 at 14:09
0

While using imagemagick-no-hdri and the default rmagick gem the pie graphs would become black and white. I was able to fix this issue by doing the following

Install imagemagick
git clone git@github.com:rmagick/rmagick.git
gem build rmagick.gemspec
gem install ./rmagick-2.13.2.gem
b00stfr3ak
  • 303
  • 1
  • 4
  • 10