On my chart I am trying to change the start point for my graph but does not work:
series: [{
name: 'Difficulty',
connectNulls:true,
color: '#FF0000',
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= 2.weeks.ago.at_midnight.to_i * 1000 %>,
data: [<% HomeworkStudent.where(:school_user_id => current_user.school_user.id).order('updated_at ASC').each do | homework_student| %>
[Date.parse(<%= homework_student.updated_at.to_json.html_safe %>), <%= homework_student.difficulty.to_json.html_safe %>],
<% end %>]
},
My chart works but pointStart is ignored. As above I am trying to use updated_at attribute in my table. I am aware the above code is probably not the ideal way in which to get and render data with Highcharts so would welcome any suggestions to clean it up too.
What changes would I have to make to get pointStart to work?
Thanks
First off, you need to change your x-axis
in data to be in epoch or change the interval in the graph to not be in miliseconds (epoch time).
So, your data should be more like:
data: <%= HomeworkStudent.
where(:school_user_id => current_user.school_user.id).
order('updated_at ASC').map {|e| [e.updated_at.to_i * 1000, e.id]}.
to_a.to_json.html_safe %>
Maybe you should also add a filter as to what you select. It shouldn't be older than two weeks ago:
data: <%= HomeworkStudent.
where(:school_user_id => current_user.school_user.id).
where('updated_at > ?', 2.weeks.ago.at_midnight).
order('updated_at ASC').map {|e| [e.updated_at.to_i * 1000, e.id]}.
to_a.to_json.html_safe %>
Other than that, you could of course have labels that are not numeric, but actual words. This is a bit more elaborate...
... or not...
You skip (like in "not use at all") the following:
pointInterval: <%= 1.day * 1000 %>,
pointStart: <%= 2.weeks.ago.at_midnight.to_i * 1000 %>,
And use data-value pairs in your data array:
data: <%= HomeworkStudent.
where(:school_user_id => current_user.school_user.id).
where('updated_at > ?', 2.weeks.ago.at_midnight).
order('updated_at ASC').
group_by {|e| e.updated_at.to_date}. # Group them rails-wise, not db-engine specific
map {|e| [e.first.to_s, e.second.sum(&:difficulty)] }. # get date and sum of difficulties, format e.first as you wish with **strftime**
to_json.html_safe %>