Install the plugin:
script/plugin install git://github.com/jpemberthy/ezgraphix.git
Run the tasks: (it will move the necessary files to use the plugin)
rake ezgraphix:setup # run from your project's root
After the installation include the FusionCharts.js in each layout that will render ezgraphix:
<%= javascript_include_tag "FusionCharts" %>
and that’s it!.
In your Controller:
For single series charts:
def index @g = Ezgraphix::Graphic.new @g.data = {:ruby => 1, :perl => 2, :smalltalk => 3} end
or you can specify the data directly in the constructor:
def index @g = Ezgraphix::Graphic.new(:data => {:ruby => 1, :perl => 2, :smalltalk => 3}) end
For multiseries charts:
In this case you have multiple values for each serie. Also you need to specify categories (labels). In the example below there are 2 series “Registrations” and “Payments” and values are divided into 7 months (labels) with a value for each serie/month.
def index @g = Ezgraphix::Graphic.new(:c_type => 'mscol3d') @g.data = { "Registrations" => [4,2,12,7,0,3,6], "Payments" => [7,3,5,2,1,0,9] } @g.labels = ["March", "April", "May", "June", "July", "August", "September"] end
There are 2 ways to pass render options:
1. When the Graphic object is created, you can define it also as:
@g = Ezgraphix::Graphic.new(:w => 200, :h => 300, :c_type => 'bar3d', :div_name => 'my_chart_tag_name')
The defaults are:
{:c_type => ‘col3d’, :w => 300, :h => 300, :div_name => ’ez_graphic’}
At the moment, you can render the following graphics:
Single Series
Column 2D => :c_type => 'col2d' Column 3D => :c_type => 'col3d' Bar 2D => :c_type => 'bar2d' Pie 2D => :c_type => 'pie2d' Pie 3D => :c_type => 'pie3d' Line => :c_type => 'line' Doughnut 2D => :c_type => 'doug2d'
Multi Series
MultiSeriesLine => :ctype => 'msline' MultiSeriesColumn3D => :ctype => 'mscol3d' MultiSeriesColumn2D => :ctype => 'mscol2d' MultiSeriesArea2D => :ctype => 'msarea2d' MultiSeriesBar2D => :ctype => 'msbar2d'
2. Anytime you want, by accessing the render_options attribute.
@g.render_options(:caption => 'cool languages', :w => 400) #Merges new options with the last configuration.
In your view.
Add the following line wherever you want to render the graphic.
<%= render_ezgraphix @g %>
or just
<%= @g %>
Tests
rake spec #run from the plugin's
Note.
Full set of render_options are specified in the rdoc, and more chart’s support will be included soon!.
Pending
Full and detailed specs.
A Ruby gem to generate flash based graphics for rails applications using a free and customizable chart’s set.
Copyright © 2008 Juan Esteban Pemberthy, released under the MIT License.
EzGraphix uses FusionCharts Free, It’s license is specified in the FusionChartsFreeLICENSE file.
Fork and feel free to contribute!
(The MIT License)
Copyright © 2008 Juan Esteban Pemberthy
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
‘Software’), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED ‘AS IS’, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.