Skip to content Skip to sidebar Skip to footer

Highcharts, Rails - Way To Set Start Point For Graph?

On my chart I am trying to change the start point for my graph but does not work: series: [{ name: 'Difficulty', connectNulls:true, color: '#FF0

Solution 1:

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 %>

Post a Comment for "Highcharts, Rails - Way To Set Start Point For Graph?"