nvd3 reusable charts for rails 3
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


NVD3 Rails - reusable charts for rails 3


To include nvd3-rails into your rails project add

gem "nvd3-rails", :git => "git@github.com:adeven/nvd3-rails.git", :submodules => true

To your Projects Gemfile.

To add the necessary javascript files into your asset pipeline add

//= require nvd3-rails

in app/assets/javascripts/application.js

also add

*= require nvd3-rails

in app/assets/stylesheets/application.css

Note as of today nvd3 clutters the model naming e.g. lineWithFisheyeChart.js and lineChart.js export their model both as lineChart. If you only need a subset of models e.g. lineChart you can add

//= require nvd3/lib/d3.v2
//= require nvd3/src/core
//= require nvd3/src/tooltip
//= require nvd3/src/utils.js
//= require nvd3/src/models/lineChart
//= require nvd3/src/models/legend.js
//= require nvd3/src/models/axis.js
//= require nvd3/src/models/scatter.js
//= require nvd3/src/models/line.js

to your application.js

Contribution Guide

Updating Submodules

The repository uses submodules following are the steps to manually get the submodules:

git clone https://github.com/adeven/nvd3-rails.git
cd nvd3-rails
git submodule init
git submodule update


git clone https://github.com/adeven/nvd3-rails.git
cd nvd3-rails
git submodule update --init


git clone --recursive https://github.com/adeven/nvd3-rails.git
cd nvd3-rails

If you want to work inside a submodule, it is possible, but first you need to checkout a branch:

cd vendor/assets/javascripts/nvd3
git checkout master

After you've committed your changes to the submodule, you'll update the nvd3-rails project to point to the new commit, but remember to push the submodule changes before pushing the new nvd3-rails commit:

cd vendor/assets/javascripts/nvd3
git push origin master
cd ..
git add vendor/assets/javascripts/nvd3
git commit


If you want to purge your working directory back to the status of upstream, following commands can be used (remember everything you've worked on is gone after these):

git reset --hard upstream/master git clean -fdx

Using a local copy during development

Nvd3-rails gets added as a Rails::Engine to your project.

Generally during development you want your main application to include a local development copy of your engine. You should be able to add gem groups for each Rails environment to your Gemfile, like this:

group :development do
    gem "nvd3-rails", :path => "../nvd3-rails"

group :production do
    gem "nvd3-rails", :git => "git://github.com/adeven/nvd3-rails.git"

In Bundler 1.1 and earlier, that generates this error message: "You cannot specify the same gem twice coming from different sources." This should be fixed in 1.2 https://github.com/carlhuda/bundler/issues/751

There are several work arounds for this, however I sugest to update to the latest version of bundle.