Rails 3 Wrapper for flot an ...
Attractive JavaScript charts for jQuery http://www.flotcharts.org/ https://github.com/flot/flot
Just add the line
gem 'flot-rails', :git => "https://github.com/Kjarrigan/flot-rails.git"
in your Gemfile and run
bundle install
Modify the application.js
like shown below:
//= require jquery
//= require jquery.flot
//= require jquery.flot.pie
Then use the pure javascript as shown here: https://github.com/flot/flot/blob/master/API.md or with my little RailsHelper:
module ApplicationHelper
include Flot
end
<!-- views/my_controller/index.html.erb -->
<%= pie_chart [{label: 'Hello World', data: 50}, {label: 'Foo', data: 25}, {label: 'Bar', data: 25}] %>
If you prefer placing your scripts in header instead of the body, then use something like this:
<!-- views/my_controller/index.html.erb -->
<%= chart(@chart_data, split: true, grid: {hoverable: true}) %>
<%= yield_chart_script_at :flot %>
and append a yield in your layout's head:
<!-- views/layouts/application.html.erb
<head>
<%= yield :flot %>
</head>