Looking to a gem that adds gtraphing capabilities to prawn, I found this one but it seems a litle outdated. Is there any more active gem for that?
There is nothing very active for graphing inside Prawn directly, but Gruff is an active gem which is highly configurable and will allow you to make all kinds of graphs.
In fact prawn-graph is basically a wrapper around gruff!
My advise is to use gruff to generate the required charts and graphs then embed them as images in Prawn document.
So the code would look something like this:
g = Gruff::Line.new(400)
g.title = "Transparent Background"
g.theme = {
:colors => ['black', 'grey'],
:marker_color => 'grey',
:font_color => 'black',
:background_colors => 'transparent'
}
g.labels = {
0 => '5/6',
1 => '5/15',
2 => '5/24',
3 => '5/30',
}
g.data(:apples, [-1, 0, 4, -4])
g.data(:peaches, [10, 8, 6, 3])
g.write(path_to_save)
Prawn::Document.generate("graphed-pdf.pdf") do
text "The image will go right below this line of text."
image "#{path_to_save}"
end
@eggie5 Regarding using gruff with prawn to insert an image without saving it to disk, it's pretty simple:
image StringIO.new(g.to_blob)
I created a Prawn Graphing library called PrawnCharts that only depends on Prawn and does not rely on rMagick and ImageMagick. rMagick and ImageMagick are annoying dependencies (big files, painful to install, etc.) and create larger files compared to a native solution like PrawnCharts.
Here is an example of a graph I generated with PrawnCharts:
Feel free to submit pull requests - I will merge them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With