Question

I am trying to follow along with the file here as an example: https://github.com/shutterstock/rickshaw/blob/master/examples/multi.html.

My goal is to instead of using the data randomly generated, to use the data from an existing table in my rails app. In particular, if I have the code:

 name: 'heat index',
  data: seriesData.shift(),
  color: 'rgba(255, 127, 0, 0.4)',
  renderer: 'stack'

I am looking to use something along the lines of

data: <%= @mytablename.all %> 

But this isn't working. Can someone point me to some rickshaw sample code that leverages existing rails tables rather than hardcoding series into a graph? Also, if the fact that I am asking this question reveals I don't have some fundamental knowledge of Rails, please let me know as I am still learning and want to understand as much as I can.

Thanks!

Was it helpful?

Solution

http://railscasts.com/episodes/324-passing-data-to-javascript?view=asciicast

I solved this by using the gon gem as described in the railscast episode above. See below for a basic idea of what the resulting dataseries is that can be plugged into many of the Rickshaw templates.

    data:  [
            {x: gon.xval [1], y: gon.yval[1] },
            {x: gon.xval [2], y: gon.yval[2] }

            ]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top