I am trying to graph data that I am pulling from an ActiveRecord query in Ruby on Rails. The JavaScript charting library (amcharts) accepts data in the following form:
var chartData = [{
date: new Date(2012, 0, 1),
products: 227
}, {
date: new Date(2012, 0, 2),
products: 371
}]
How do I parse a date string in the format YYYY-MM-DD and create a JavaScript Date object from the query below? I've seen this tutorial but I'm having trouble figuring out how to write a function to correctly parse the json output.
create_table :products do |t|
t.date :date
end
<% a = Product.select("date(date) as date, count(id) as products").group("date(date)").to_a.to_json %>
function parseCSV(data)
to parse the CSV column to a JavaScript date object. I guess my question is, how to a write a similar function to parse the json above?<% a = Product.select("date(date) as date, count(id) as products").group("date(date)").to_a.to_json %>
to achieve the same result. Parsing a json array instead of a CSV file.