PhantomGraph
PhantomGraph helps complex process to generate javascript charts to image or pdf without requesting or rendering view to the application. PhantomGraph is pure server-side process by using phantomjs and suitable for background process. It is lighweight solution for wkhtmltopdf alternative.
Installation
gem 'phantom_graph'
or
gem install 'phantom_graph'
Do not forget to install phantomjs
See http://phantomjs.org/download.html on how to install phatomjs
How To Use
add initialize file to “config/initializers/phantom_graph.rb” “‘
PhantomGraph.configure do |config|
# default: `which phantomjs` or `bundle exec which phantomjs`
config.phantomjs = "/usr/local/bin/phantomjs"
# default: false
config.logger = true
# Some javascript plugins are included in Gem
# if you override please change configuration below
# config.highcharts_convert_path = "/path/app/js/highcharts-convert.js"
# config.highcharts_theme_path = "/path/app/js/highcharts-theme.js"
# config.highcharts_path = "/path/app/js/highcharts.js"
# config.highstock_path = "/path/app/js/highstock.js"
# config.jquery_path = "/path/app/js/jquery.js"
end
For more samples of json string or file please check:
* highchart json, please check: http://www.highcharts.com/demo/
* highstock json, please check: http://www.highcharts.com/stock/demo
Highchart
# sample script: spec/phantom_graph/convert/highchart_spec.rb
= {image_file_path: "#{Rails.root}/tmp", filename: "output.png"}
callback_json = "customCallback"
highchart = PhantomGraph::Convert::Highchart.new(json_str, , callback_json)
highchart.result
Highstock
# sample script: spec/phantom_graph/convert/higstock_spec.rb
= {image_file_path: "/path/project/public", filename: "report.pdf"}
highstock = PhantomGraph::Convert::Highstock.new(json_str, , callback_json)
highstock.result
Outputs: PDF, SVG, PNG, JPG
Default options for Highstock and Highchart:
{width: 1200,
scale: 0.5,
constr: "Chart",
json_file_path: "/tmp",
image_file_path: "/tmp",
filename: nil,
callback_file_path: "/tmp"
}
TODO
-
Add Google Chart Module
-
Add Custom Theme Support
-
Add Synchronous Processor