dvandersluis / amcharts.rb

Ruby/Rails wrapper for Amcharts
MIT License
12 stars 9 forks source link

AmCharts.rb Gem Version Build Status

Ruby on Rails wrapper for creating AmCharts charts.

Usage

A chart is represented by a subclass of AmCharts::Chart (ie. Pie or Serial), which is initialized with a data collection (should be an array of homogeneous hashes), and some settings passed into a block:

chart = AmCharts::Chart::Serial.new(data) do |c|
  add_title 'My Fancy Chart', size: 18
  loading_indicator!

  c.dimensions = '800x600'

  legends.new do |l|
    l.position = 'right'
    l.value_text = '[[percents]]%'
  end

  scrollbar {}
end

The setup block accepts a number of methods for ease of setting up a chart, and accepts any other assignment method as a setting that will be passed directly to AmCharts when the chart is rendered. Chart components including graphs, legends, axes, scrollbars and cursors can also be added and configured using inner blocks. Listeners can also be defined in a similar manner.

Values in the setup block can be numeric or string literals (which will be passed along as is); symbols (which will be given to I18n.t before being rendered); procs (which will be executed); or the function() method (which will act as a literal javascript function).

An AmCharts::Chart object can then be rendered using the amcharts helper:

amcharts(chart, 'id-of-container')

If the container ID given doesn't already exist in the page, it will be automatically created before the chart is rendered by AmCharts.

Chart setup methods

Defining a chart

Note about the Version Number

The version number correlates to the version of AmCharts that is included (ie. 3.1.1.0 is the first release of amcharts.rb which uses AmCharts v3.1.1)

Using a Commercial AmCharts license

If you have purchased the commercial version of AmCharts, place the amcharts.js file it comes with inside a javascripts/amcharts directory within (app|lib|vendor)/assets, so that it will be used instead of the free version that is included in this gem.

Installation

Add this line to your application's Gemfile:

gem 'amcharts.rb'

And then execute:

$ bundle

Or install it yourself as:

$ gem install amcharts.rb

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Acknowledgments