score:1

Accepted answer

to convert your datetime object to the JS milliseconds convention, just call

DateTime.now.to_i*1000 

or in your case

def index
  @data = {"status" => "ok", "data" => [{"2014-06-16 16:00:00" => 24.2},{"2014-06-17 12:00:00" => 30.2},{"2014-06-18 17:00:00" => 42.9}]}
  d = []
  @data['data'].each do |data|
    d << [DateTime.parse(data.keys.first).to_i*1000, data.values.first]
  end 

  @chart = LazyHighCharts::HighChart.new('chart') do |f|
    f.chart(:height => '400')
    f.yAxis [:title => {:text => "Temperature", :margin => 20, style: { color: '#333'}}]
    f.xAxis(type: 'datetime')
    f.series(:type => 'area', :name => '24hrs', :data => d)
  end
end

score:1

Your dates should be timestamps (time in miliseconds like 12323311000) not in the form like this: "2014-06-16 16:00:00" So you need to convert it.


Related Articles