Skip to content

Latest commit

 

History

History
67 lines (46 loc) · 1.83 KB

README.textile

File metadata and controls

67 lines (46 loc) · 1.83 KB

jqPlot-rails

NOTE This is a Rails 2.x plugin and as such is outdated now!

jqPlot is an excellent javascript charting library based on jQuery. jqPlot-rails is a wrapper plugin which makes using it in RoR somewhat easier.

Installation

Install the plugin:

script/plugin install git://github.com/kammerer/jqplot-rails.git

Copy required files to public directory:

rake jqplot:install

Copied files include jQuery library and jqPlot itself (it consists of several javascript files and one CSS file).

Add following includes to your layout (view template examples use Haml syntax):


  /[if IE]
    = javascript_include_tag "excanvas.min.js"

  = javascript_include_tag "jquery-1.3.2.min"
  = javascript_include_tag "jqplot/jquery.jqplot.min"

  = stylesheet_link_tag "jqplot/jquery.jqplot.min"

Optionally add includes for jqPlot plugins:


  = javascript_include_tag "jqplot/plugins/jqplot.barRenderer.min"
  = javascript_include_tag "jqplot/plugins/jqplot.categoryAxisRenderer.min"

Usage

In your view you can do this to plot a chart:

 
  #chart
  = javascript_tag
   = update_page do |page|
     - page << plot('chart', [[[0, 0], [1, 2], [2, 5], [3, 1]]],
                    :seriesDefaults => { :color => "#a55" })

All options should be passed as pure Ruby code – they will be converted to proper javascript.

In order to specify a renderer use plot_renderer helper:


  plot('chart', data, :series_defaults => { :renderer => plot_renderer(:bar) },
                      :axes => { :xaxis => { :renderer => plot_renderer(:category_axis) } })

For detailed explanation of all available options consult jqPlot documentation