Reputation: 308
I am following Railscast #223 to try to get some simple line graphs into my Rails 3.2.9 site using Morris.js and Raphael. I've downloaded the raphael and morris javascript files and added them to the vendor/assets/javascripts folder, then added the relevant lines to the application.js:
//= require raphael
//= require morris
I then created a simple HTML div for the chart:
<div id="annual"></div>
And added the relevant CoffeeScript to the associated javascript file (tenants.js.coffee):
jQuery ->
Morris.Line
element: 'annual'
data: [
{y: '2012', a: 100}
{y: '2011', a: 75}
{y: '2010', a: 50}
{y: '2009', a: 75}
{y: '2008', a: 50}
{y: '2007', a: 75}
{y: '2006', a: 100}
]
xkey: 'y'
ykeys: ['a']
labels: ['Series A']
The page loads fine but without producing the graph. I'm new to CoffeeScript so I'm not sure how to debug this. I'm sure it's something simple I'm missing.
Thanks!
Upvotes: 1
Views: 1279
Reputation: 1257
If were are using simple js file, example annual.js, there are use code:
jQuery(function() {
return Morris.Line({
element: 'annual',
data: [
{y: '2012', a: 100},
{y: '2011', a: 80},
{y: '2010', a: 75},
{y: '2009', a: 70},
{y: '2008', a: 65},
{y: '2007', a: 60},
{y: '2006', a: 55}
],
xkey: 'y',
ykeys: ['a'],
labels: ['Series A']
});
});
For converting js to coffee = http://js2coffee.org/
Upvotes: 1
Reputation: 447
Try this solution in CoffeeScript:
Morris.Line({
element: 'annual'
data: [
{y: '2012', a: 100}
{y: '2011', a: 75}
{y: '2010', a: 50}
{y: '2009', a: 75}
{y: '2008', a: 50}
{y: '2007', a: 75}
{y: '2006', a: 100}
]
xkey: 'y'
ykeys: ['a']
labels: ['Series A']
})
Upvotes: 1