I am working on an application where I am fetching the weather information from OpenWeatherMaps API and then plotting it on graphs using FlotJS.
The data is coming from:
http://api.openweathermap.org/data/2.5/forecast?lat=39.77476949&lon=-100.1953125
Where the lat, lon are dynamically generated. You can go to the link to get an idea of what kind of JSON response is sent back.
I am trying to construct the arrays first in order to pass them into the data object while plotting the graph like so:
var temp = [];
var humidity = [];
var rain = [];
$.each(response.list, function(i, item){
if(moment(item.dt, 'X').isSame(moment(), 'day')){
temp.push([moment(item.dt, 'X').valueOf(), parseFloat(item.main.temp)]);
humidity.push([moment(item.dt, 'X').valueOf(), parseFloat(item.main.humidity)]);
rain.push([moment(item.dt, 'X').valueOf(), parseFloat(item.rain.3h)]);
}
});
temp
and humidity
were working fine. I cannot add precipitation. The precipitation values are in the rain
object in 3h
and when I try to push it into the array, I get a console error saying:
SyntaxError: identifier starts immediately after numeric literal
How to go around this problem?