I’m trying to display a chart titled “Purchases over Time” using Highcharts in my Rails 3.1 app.
In my function I am returning an array made up of the created_at date (in date format) and value of purchase (in integer format). When I display the function in a view it looks like this:
[2012-01-065002012-01-072502012-01-08130...]
It translates to: [[2012-01-06, 500], [2012-01-07, 250], [2012-01-08, 130]]
In the view within the Highcharts JS code I have the following for the series:
series: [{
name: '<%= User.product_names_by_user(current_user) %>',
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= User.from_the_first_purchase_date(current_user) %>,
data: <%= User.purchases_over_time(current_user) %>
}]
from_the_first_purchase_date is a function that simply returns the very first purchase date in date format.
purchases_over_time is the function in question (as described above).
From my understanding (or lack there of) of the Highcharts API, I can use a list of arrays with two values as the data of a chart (Highcharts docs) whereas the first value of the array represents the x value and the second is the y value.
So, I was hoping to be able to chart the purchase value over time. In the view, my chart shows up but no data is displayed and there are no plot points visible.
I’ve also tried returning the array in the following format to no avail:
[["2012-01-06", 500], ["2012-01-07", 250], ["2012-01-08", 130]]
Any suggestions?
Thank you.
Or you can convert the datetime in your controller by
Date.parse, then use thelazy-high-chartgem to send the data toHightChartin viewer. Here is the site forlazy-high-charthttps://github.com/michelson/lazy_high_charts.