Chartr is a bit of Ruby glue to interface with the Plotr Javascript library, available here: solutoire.com/plotr/
Chartr is written by David N. Welton <davidw@dedasys.com> for DedaSys LLC.
After you have installed Chartr in vendor/plugins/chartr, the first thing you need to do is install the Plotr javascript files that ship with Chartr:
rake chartr:install_js
This installs (overwriting them if they already existed) these files in public/javascripts/ - plotr_uncompressed.js, excanvas.js, and prototype1_5_1_1.js, which is necessary because of compatibility problems between Plotr and Prototype 1.5.0.
Chart data takes the form of a list of lists, where the sublists take the form x-label, y-value. For example:
data = [["1960", 1000], ["1970", 5000], ["1980", 20000], ["1990", 22000]]
To create a chart, all we have to do is this:
@barchart = BarChart.new
@barchart.options = { :legend => { :position => { :left => '120px' }}}
@barchart.datasets << Chartdata.new(data, "Number/Decade")
Now, in a Rails view, we can do this:
<div class="chart">
<canvas id="results_chart" height="400" width="1000"></canvas>
</div>
<script type="text/javascript">
<%= @barchart.output('discvar', 'results_chart) -%>
</script>
Which should produce something like this: