Saturday 15 February 2014

ruby on rails - Parsing JSON Data for Lazy Highcharts -



ruby on rails - Parsing JSON Data for Lazy Highcharts -

i'm having issues parsing json info high charts using lazy highcharts gem. i'm trying select info lastly 7 days, or 1 week ago. @ stage application hangs , doesn't load code below.

i loading json info link.i have tried pointstart option, doesn't seem work.

any help appreciated.

json

{"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}]} etc

controller

@data = oj.load(open(@temperature.url).read) results = [] @data['data'].each |data| results << ((7.day.ago.to_i * 1000)..(date.today.to_i * 1000)).map { |date| [datetime.parse(data.keys.first).to_i * 1000 == date, data.values.first] } end @graph = lazyhighcharts::highchart.new('graph') |f| f.chart(:height => '400', width: '860') f.yaxis [:title => {:text => "temperature, :margin => 20, style: { color: '#333'}}] f.series(:type => 'line', :name => 'temperature', pointstart: 7.day.ago.to_i * 1000, data: results, marker: {enabled: false}, :color => '#00463f' ) f.xaxis(:type => 'datetime', tickinterval: 1.day.to_i * 1000, :tickmarkplacement => 'on', :startontick => true ) f.legend({:align => 'center', :verticalalign => 'top', :y => 0, :borderwidth => 0, style: {color: "#333"}}) end

i have solved this. if 1 interested added;

min: 1.weeks.ago.at_midnight.to_i * 1000

to xaxis.

ruby-on-rails json highcharts ruby-on-rails-3.2 lazy-high-charts

No comments:

Post a Comment