I'm using Highcharts to display other graphs from csv's in my application, but now I have to access JSON data from a url (test.com/data/data1,temp) and i'm not sure how to best tackle this scenario.
The JSON data is formatted as such:
{"status": "ok", "data": [{"2013-10-01 00:00:00": 19.6}, {"2013-10-01 01:00:00": 19.1}, {"2013-10-01 02:00:00": 18.4}, {"2013-10-01 03:00:00": 17.9}, {"2013-10-01 04:00:00": 17.5}, {"2013-10-01 05:00:00": 17.2}, {"2013-10-01 06:00:00": 17.2}, {"2013-10-01 07:00:00": 17.4}]}
and i have set up a form to input the url (as there are 30 locations) to generate each chart. I'm also not sure on how best to separate the two results, e.g.. the first being 'date' the second 'temperature'.
@data = JSON.parse(open("test.com/data/data1,temp").read) @dates = Array.new @temperatures = Array.new @data['data'].each do |d| @dates.push(d.keys) @temperatures.push(d.values) end @graph = LazyHighCharts::HighChart.new('graph') do |f| f.chart(:height => '300') f.yAxis [:title => {:text => "Temperature", :margin => 20, style: { color: '#333'}}] f.series(:type => 'line', :name => 'Temperature', :data => @temperatures) f.xAxis(:categories => @dates, labels: {overflow: 'justify', :rotation => 90, :step => 10} ) end
Any help would be appreciated.