d3_charts
Rails helpers for building SVG charts using the d3 library.
Installation
Add this line to your application's Gemfile:
gem 'd3_charts'
And then execute:
$ bundle
Or install it yourself as:
$ gem install d3_charts
To make it work you need to require the javascripts in application.js
:
//= require d3_charts
To add some basic colouring of pie charts, add the the following in application.css
:
*= require 'd3_charts'
Usage
Pie charts
= pie_chart(data, options)
Available options
are:
width
, defaults to 1000height
, defaults to 1000
Which are passed in like so:
= pie_chart(data, { width: 123, height: 123 })
Area charts
= area_chart(data, options)
Available options
are:
width
, defaults to 1000height
, defaults to 1000margin
, defaults to 25format
, the strftime format of the dates, defaults to%d/%m/%y
Which are passed in like so:
= area_chart(data, { width: 123, height: 123, margin: 25 })
TODO:
- Add more charts:
- Line Chart
- Histogram Chart
- Vertical Bar Chart
- Horizontal Bar Chart
Contributing
- Fork it ( https://github.com/tomasc/d3_charts/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request