At this time I'm programming a web based user interface for an autonomous plant-box (nothing criminal :) )
We have a SPS-Based controller which logs periodically temperature and humidity data into a SQL-database.
I wrote a small PHP script which retrieves some of the most recent rows and gives it back to me as an array. So far so good, I've been able yet to get this data into my HTML page with a $.getJSON(). I know that's outdated, I should better use an ajax function, but that's not the problem at the moment.
My PHP script returns an array in JSON format:
[
{"id":"321","datum":"12.12.2016","time":"19:12","temp_innen":"19.8","feucht_innen":"51.7"},
{"id":"322","datum":"12.12.2016","time":"19:22","temp_innen":"19.8","feucht_innen":"51.7"},
{"id":"323","datum":"12.12.2016","time":"19:32","temp_innen":"19.8","feucht_innen":"51.7"},
{"id":"324","datum":"12.12.2016","time":"19:42","temp_innen":"19.8","feucht_innen":"51.7"},
{"id":"325","datum":"12.12.2016","time":"19:52","temp_innen":"19.8","feucht_innen":"51.6"},
{"id":"326","datum":"12.12.2016","time":"20:02","temp_innen":"19.8","feucht_innen":"51.6"},
{"id":"327","datum":"12.12.2016","time":"20:12","temp_innen":"19.8","feucht_innen":"51.5"},
{"id":"328","datum":"12.12.2016","time":"20:22","temp_innen":"19.8","feucht_innen":"51.6"},
{"id":"329","datum":"12.12.2016","time":"20:32","temp_innen":"19.8","feucht_innen":"51.4"},
{"id":"330","datum":"12.12.2016","time":"20:42","temp_innen":"19.8","feucht_innen":"51.4"},
{"id":"331","datum":"12.12.2016","time":"20:52","temp_innen":"19.8","feucht_innen":"51.4"},
{"id":"332","datum":"12.12.2016","time":"21:02","temp_innen":"19.8","feucht_innen":"51.4"}
]
Now I just want to extract some of the columns into single arrays. It should look like this:
Every column which has i.e. the tag "datum" should be in one array, every "time" tag and so on.
Goal is to make a chartjs line chart which shows me the temperature and humidity for a fixed time.
What I've tried so far:
$.getJSON( "/php/logabfrage.php", function(data) {
var Datum = [], Zeit = [], Temp = [], Hum = [];
$.each(data, function(index, value) {
Datum.push(new Date(data.datum));
Zeit.push(new Date(data.zeit));
Temp.push(parseFloat(data.temp_innen));
Hum.push(parseFloat(data.feucht_innen));
});
});
but this doesnt get me the result I want. maybe someone can help me or take me to the right answered question here, because I didnt find something similar to my problem in the internet.
In the end it should look like this:
var date = [date1, date2, ..., dateN];
var temp = [temp1, temp2, ..., tempN];
and so on.

$.getJSON()is an Ajax function.data.datumwhat...datais an array...but this doesnt get me the result i want.but it is not clear what the desired result is. Please explain what you expect how it should look like and how this differes from you current result.var Date [1: date1, 2: date2,..., n: date n]- this is not a valid array, but it would be better to construct a plain array likevar dateItems = [date1, date2,..., date n]value.datuminstead ofdata.datuminsideeach