Im loading Data from Googlesheets
to fusioncharts
in my rails app.
I use Jquery
to Fetch the data from the google sheets as seen in this tutorial https://www.sitepoint.com/interactive-javascript-charts-using-data-from-google-sheets/
Rails always gives me this error undefined local variable or method 'parsedData' for #<GreetingsController:0x007fdb862e9cf8>
when I try to fetch the data from the pasedData
variable like this.
data: parsedData
I'm not sure on what I'm doing wrong here, this is the first time I'm using JSON to load data to fusioncharts in rails app. Any help would be much appreciated
here is the Jquery snippet were the googlesheets gets turned into JSON.
var spreadsheetId = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
url = "https://spreadsheets.google.com/feeds/list/" +
spreadsheetId +
"/od6/public/basic?alt=json";
$.get({
url: url,
success: function(response) {
var data = response.feed.entry,
len = data.length,
i = 0,
parsedData = [];
for (i = 0; i < len; i++) {
parsedData.push({
label: data[i].title.$t,
value: data[i].content.$t.replace('income: ', '')
});
}
}
});
Here is the fusionchart snippet from the rails controller
@chart2 = Fusioncharts::Chart.new({
type: 'bar2d',
renderAt: 'chart-container',
width: '100%',
height: '300',
dataFormat: 'json',
dataSource: {
chart: {
caption: "Highest Paid Actors",
yAxisName: "Annual Income (in milion USD)",
numberPrefix: "$",
theme: "fint",
exportEnabled: "1",
},
data: parsedData
}
})
and here is instructions about rails and fusioncharts https://github.com/fusioncharts/rails-wrapper